- What's the value of
b
?
let a = [0, 1];
let b = a;
a.push(2);
console.log(b);
- What's the result of the following and why?
typeof([]);
- What's the difference between
var
andlet
? Provide an example. - What's the result of following invocations?
// given the following object
const me = {
name: 'Adam',
hello() {
return `hello ${this.name}`;
}
};
me.hello();
const anotherMeSaysHello = me.hello;
anotherMeSaysHello();
const anotherMeSaysHello = me.hello;
anotherMeSaysHello.call(me);
const anotherMeSaysHello = me.hello;
anotherMeSaysHello.call({name: 'Regina'});
const anotherMeSaysHello = me.hello.bind(me);
anotherMeSaysHello();
- What's the result of running every example? Explain the difference between them.
function test () {
console.log(test);
var test = 5;
}
test();
function test () {
var test = 5;
console.log(test);
}
test();
function test () {
console.log(test);
let test = 5;
}
test();
-
Explain shadowing and provide code example that demonstrates its definition.
-
Provide code example of closure.
-
Fix the alert index exercise.
- Draw the inheritance diagram of the following. Explain the result of
console.log
statement.
let obj1 = { a: 1 };
let obj2 = Object.create(obj1);
console.log(obj2.a) // 1
- Draw the inheritance diagram of the following code.
class A {
sayA() {
console.log('A');
}
}
class B extends A {
sayB() {
console.log('B');
}
}
const a = new A();
const b = new B();
- Explain how event loop works.
- Fix the following problem.
- What's the callback hell?
- Implement the following using callbacks and promises.
function verifyBeforeRender(successCallback) {
// make 2 ajax calls at the same time
// when both of them return result, make a 3rd ajax call
// if the result if 3rd ajax request was successful, call a `successCallback`
}
- Implement HTML page with a counter and two buttons of increment and decrement. Everything in JS. File of
index.html
should contain emptybody
as an initial state.