Created
July 13, 2018 12:46
-
-
Save webislife/498af2bd9387d92c6030835c15363ea6 to your computer and use it in GitHub Desktop.
JS questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Q1 | |
console.log(typeof typeof 2); //? | |
//Q2 | |
console.log(1+2+3+'1'); //? | |
//Q3 | |
console.log(1+[]+1+{}) //? | |
//Q4 | |
console.log(!1+!2); //? | |
//Q5 | |
var n = 10, | |
obj1 = { | |
value: 'first val' | |
}, | |
obj2 = { | |
value: 'second val' | |
}, | |
obj3 = obj2; | |
function trans(n, obj1, obj2) { | |
n = n*10, | |
obj3 = obj1; | |
obj1 = obj2; | |
obj2.value = 'third value'; | |
} | |
trans(n, obj2, obj1); | |
console.log( n ) //? | |
console.log(obj1.value) //? | |
console.log(obj2.value) //? | |
console.log(obj3.value) //? | |
//Q6 | |
var a = [1, 2]; | |
b = [3, 4]; | |
Array.prototype.push.call(a, b); | |
console.log(a) //? | |
console.log(b) //? | |
//Q7 | |
function count(count) { | |
var res = [] | |
for (var i = 0; i < count; i++) { | |
res.push(function() { console.log(i) }) | |
} | |
return res | |
} | |
console.log(count(5)[2]()) //? | |
//Q8 - write calc fn | |
calc(2, 5) //result 7 | |
calc(2)(5) //result 7 | |
//Q9 | |
function fn(a,b,c,d,e) { return console.log(arguments.length) } | |
console.log(fn(1, undefined,3,undefined)) //?? | |
//Q10 | |
var a = 2; | |
function a(b) { return b }; | |
console.log(a); //?? | |
//Q11 - write a sequence of numbers | |
function showMe() { | |
console.log('1'); | |
setTimeout(function(){console.log('2');}, 0) | |
console.log('3'); | |
setTimeout(function(){console.log('4');}, 0) | |
console.log('5'); | |
} | |
showMe(); | |
//Q12 - write searchEqual names fn | |
var cities = ['london', 'donlon', 'tokio', 'moscow', 'paris', 'iokto', 'stpetersburg'] | |
searchEqual(cicites); | |
//true result | |
[ | |
['london', 'donlon'], | |
'moscow', | |
'paris', | |
['tokio', 'iokto'], | |
'stpetersburg' | |
] | |
//Q13 write isPalindrom fn | |
isPalindrom('око') //true | |
isPalindrom('окунь')//false | |
isPalindrom('Аргентина манит негра') //true | |
isPalindrom('Madam, I’m Adam') //true | |
//Q14 write reverseString fn for any strings | |
'nodnol'.reverseString(); //London | |
//Q15 write greyscale fn | |
greyScale('#ffcc00'); //#999999 | |
greyScale('#00baff'); //#939393 | |
//Q16 write sleep fn | |
demo(); | |
async function demo() { | |
console.log("Hello!"); | |
await sleep(1000); | |
console.log("1 second after start"); | |
await sleep(2000); | |
console.log("3 second after start"); | |
} | |
function sleep() { | |
//write here | |
} | |
//Q17 | |
var a={}, | |
b={key:'b'}, | |
c={key:'c'}; | |
a[b]=123; | |
a[c]=456; | |
console.log(a[b]); //? | |
//Q18 | |
var y = 1; | |
if (function f(){}) { | |
y += typeof f; | |
} | |
console.log(y); //? | |
//Q19 | |
var output = (function(x){ | |
delete x; | |
return x; | |
})(0); | |
console.log(output); //? | |
//Q20 | |
var Employee = { | |
company: '8bit' | |
} | |
var emp1 = Object.create(Employee); | |
delete emp1.company | |
console.log(emp1.company); //? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment