What is the output of the following code? ```js var x = 1; function foo() { console.log(x); var x = 2; } foo(); ```
Variables Types Collections
Question · Easy
Which of the following correctly describes the difference between `let` and `var`?
What is the output of this code? ```js const arr = [1, 2, 3]; arr.push(4); console.log(arr.length); ```
Tech Exam Prep Podcast
Listen on Spotify
Podcast
What does the following destructuring assignment produce for `b`? ```js const [a, b = 10, c] = [1, undefined, 3]; console.log(b); ```
Question · Medium
What is the result of `typeof null` in JavaScript?
Given the code below, what is logged? ```js const map = new Map(); map.set('a', 1); map.set('b', 2); console.log(map.size); ```
Which statement about `Set` is correct?
What is the output? ```js const obj = { a: 1, b: 2, c: 3 }; const { a, ...rest } = obj; console.log(rest); ```
What does `Number('') === 0` evaluate to?
Question · Hard
Which of the following creates a shallow copy of an array `arr`?
What is the output of the following? ```js const sym1 = Symbol('desc'); const sym2 = Symbol('desc'); console.log(sym1 === sym2); ```
What is the difference between `Map` and `WeakMap`?
What is the output? ```js let a = 5; let b = a++; console.log(a, b); ```
What will the following generator function log? ```js function* gen() { yield 1; yield 2; yield 3; } const it = gen(); console.log(it.next().value); console.log(it.next().value); ```
What does `JSON.parse(JSON.stringify({ a: undefined, b: 1 }))` return?
What is the output? ```js function outer() { let count = 0; return function inner() { count++; return count; }; } const increment = outer(); console.log(increment()); console.log(increment()); ```
Objects Functions Classes
What is the value of `this` inside an arrow function defined in the global scope (in strict mode)?
What does `Function.prototype.bind` return?
What is the output? ```js class Animal { constructor(name) { this.name = name; } speak() { return `${this.name} makes a sound.`; } } class Dog extends Animal { speak() { return `${this.name} barks.`; } } const d = new Dog('Rex'); console.log(d.speak()); ```
What is prototypal inheritance in JavaScript?
What is the result of calling a constructor function with `new`?
What does `Object.freeze()` do?
What is the output of this code? ```js const obj = { name: 'Alice', greet: function() { return `Hello, ${this.name}`; } }; const greet = obj.greet; console.log(greet()); ```
What is a higher-order function?
What is the output? ```js const handler = { get(target, prop) { return prop in target ? target[prop] : 37; } }; const p = new Proxy({}, handler); p.a = 1; console.log(p.a, p.b); ```
Which method is used to call a function with a specific `this` value and individual arguments?
What is a JavaScript closure?
What is the output? ```js function Person(name) { this.name = name; } Person.prototype.greet = function() { return `Hi, I'm ${this.name}`; }; const alice = new Person('Alice'); console.log(alice.hasOwnProperty('name')); console.log(alice.hasOwnProperty('greet')); ```
What does `Object.create(proto)` do?
What is the output of the following code using `call`? ```js function greet(greeting) { return `${greeting}, ${this.name}!`; } const user = { name: 'Bob' }; console.log(greet.call(user, 'Hello')); ```
What is the output? ```js const obj = {}; Object.defineProperty(obj, 'secret', { value: 42, writable: false, enumerable: false }); console.log(obj.secret); console.log(Object.keys(obj).length); ```
What is the output? ```js const nums = [1, 2, 3, 4, 5]; const result = nums.reduce((acc, val) => acc + val, 0); console.log(result); ```
What is `IIFE` and why is it used?
What does `super()` do in a subclass constructor?
What will the following code output? ```js const obj = { value: 10, double: () => obj.value * 2 }; console.log(obj.double()); ```
Which browser API method is used to select the first DOM element that matches a CSS selector?
Browser Events
What is event bubbling?
What method stops an event from propagating further up the DOM tree?
What is the third parameter of `addEventListener` used for?
What is the output of the following Promise chain? ```js Promise.resolve(1) .then(v => v + 1) .then(v => v * 2) .then(v => console.log(v)); ```
What does `Promise.all([p1, p2, p3])` return?
What is the output? ```js async function fetchData() { return 42; } fetchData().then(v => console.log(v)); ```
How does `async/await` handle errors?
What is event delegation?
What is stored in `localStorage` compared to `sessionStorage`?
What is the output? ```js const p = new Promise((resolve, reject) => { reject(new Error('fail')); }); p.catch(err => console.log(err.message)); ```
Which Fetch API method correctly sends a POST request with JSON data?
Loading more…