1. What is JavaScript?
2. What are the differences between the following expressions:
x = y;
x == y;
x === y;
3. What is hoisting in JavaScript? Provide an example?
4. Is this valid JavaScript? Why or why not?
var x = multiply(2)(3);
5. What is 'this' keyword in JavaScript?
6. What will be the output to the console for the following?
function firstHalf() {
var qtr1 = "kickoff";
if (true){
var qtr1 = "touchdown";
qtr2 = "field goal";
}
console.log(qtr1);
console.log(qtr2);
}
function secondHalf() {
console.log(qtr1);
console.log(qtr2);
}
firstHalf();
secondHalf();
7. How do you remove a property from an object?
8. What will be the output to the console for the following?
function countDown() {
for (var index = 5; index > 0; index--){
setTimeout(function() {
console.log('Index: ' + index);
}, 5000 );
}
}
countDown();
9. What is the difference between substr and substring? Provide an example showing how to use each.
10. What will be the output to the console for the following?
function foo() {
console.log(this.bar);
}
var bar = "bar";
var biz = { bar: "biz", foo: foo };
var bang = { bar: "bang" };
foo();
biz.foo();
biz.foo.call();
biz.foo.call(bang);
11. Why would you ever wrap an entire function or source file in a function block?
12. What do the following statements return?
typeof "Hello World";
typeof [1, 2, 3].concat();
typeof {a:1};
typeof function test() {}
typeof [1, 2, 3];
typeof null;
typeof NaN;
13. What is a "closure" in JavaScript? Provide an example.
14. What is the output from the following code?
(function() {
foo = 5;
var bar = 10;
})();
console.log(foo);
console.log(bar);
15. What is the difference between a function declaration and a function expression?
16. What is the output from the following code?
(function() {
var apple = 2;
function pie() {
var apple = 3;
}
pie();
console.log(apple);
if (apple) {
var apple = 3;
}
console.log(apple);
})();
17. List all of the JavaScript data types?
18. Write a multiply function that will produce the following outputs when invoked.
console.log( multiply(2, 3); // output: 6
console.log( multiply(4)(5) ); // output: 20
19. What is strict mode in JavaScript? How do you implement it? Why would you use it?
20. Answer the following questions.
How do you remove the first item in an array?
How do you remove the last item in an array?
How do you add a new item to the beginning of an array?
How do you add a new item to the end of an array?
How do you remove all the entries in an array?
21. Your function takes one parameter. How would you verify that the parameter is an array?
22. What is event bubbling?