300 JavaScript Interview Mastery Questions
Dive Deep into JavaScript Theory, Syntax, and APIs, and Interview with Confidence
Text copyright 2020 Jonathan Middaugh all rights reserved.
Introduction
This book contains questions covering JavaScript syntax, rules, functionality, and theory. It is designed to help you improve upon your JavaScript knowledge as well as expose you to some edge cases and unusual situations in JavaScript. I find that these are the types of examples that really solidify a developers understanding of this fun language.
The book has a few questions specific to JavaScript running in the browser, but most questions are agnostic of environment. A few questions also include TypeScript, but they will be designated as such. The book is organized into 4 tests with each question linking to its answer in the back of the book.
As a bonus, the two links below provide another 50 free JavaScript interview mastery questions and 50 free TypeScript interview mastery question.
50 JavaScript Interview Mastery Questions (published on my Medium.com publication).
50 TypeScript Interview Mastery Questions (published on my Medium.com publication).
About the Author
If you enjoy this book and want to continue learning JavaScript with me, take a look at the following:
- My Medium.com Portfolio Filled with JavaScript articles and the occasional dev side hustle Im working on
- My YouTube Channel Same as my Medium.com portfolio, but I enjoy the interactive feel of making the videos. Plus I believe they can help different people learn in different ways
- Twitter Follow me here for news about recent articles plus whatever is interesting in the dev community
Table of Contents
Test 1 Questions
Q1.
Which of the following prints first?
setTimeout(() => {
console.log('setTimeout wins');
},0);
queueMicrotask(() => {
console.log('queueMicrotask wins');
});
A) setTimeout wins
B) queueMicrotask wins
C) Compile time error
The answer is B. Tasks from queueMicrotask are called after the callstack is empty and before the event loop is called. Tasks from setTimeout are part of the eventQueue.
Q2.
What will the code below output to the console and why?
let x = 10;
const byValue = (y) => {
y = 20;
}
byValue(x);
console.log(x);
A) 20
B) 10
C) Compile time error
Q3.
Consider the following code. What will it log to the console and why?
let x = 5;
let x = 10;
console.log(x);
A) 5
B) 10
C) It will throw a compiler error.
Q4.
Consider the following code. What does each line output?
console.log(new String("yes") === new String("yes")); // Line 1
console.log("yes" === "yes"); // Line 2
A) Line 1 prints true, Line 2 prints true
B) Line 1 prints false, Line 2 prints true
C) Line 1 prints true, Line 2 prints false
D) Line 1 prints false, Line 2 prints false
Q5.
What will the code below output to the console and why?
const x = new String("tricky");
const y = x;
console.log(x === y);
A) True
B) False
Q6.
Are arrays objects or primitives in JavaScript?
A) Objects
B) Primitives
Q7.
What is the return type of the async function below?
async function goodbye() {
return goodbye;
}
A) string
B) Promise
C) Async
Q8.
True or False? The await keyword blocks all JavaScript code execution in an app until the awaited Promise is returned.
A) True
B) False
Q9.
Recall that functions are objects in JavaScript. What does the following print?
function myFunc() {}
console.log(typeof myFunc);
A) object
B) function
C) true
D) It throws an error
Q10.
True or False? The following is valid syntax for printing goodbye.
let goodbye = async () => { return "Goodbye" };
goodbye().then(console.log);
A) True
B) False
Q11.
What of the following is not a difference between typeof and instanceof ?
A) typeof returns a type and instanceof returns a boolean
B) instanceof requires TypeScript and typeof does not
C) typeof takes the variable name on the right while instanceof takes a value on the left and right
Q12.
Which of the following resolves when all promises are fulfilled, or rejects as soon as one promise is rejected?
A) Promise.race()
B) Promise.any()
C) Promise.all()
D) Promise.resolve()
Q13.
What will the code below output to the console and why?
let x = 10;
function myFunc(y){
y = 12;
}
myFunc(x);
console.log(x);
A) 10
B) 12
C) undefined
Q14.
What does the below code output to the console and why?
console.log(11 & 3);
A) 11
B) 1
C) 2
D) 3
Q15.
What is the value of Object.[[Prototype]]?
A) Object
B) null
C) {}
Q16.
What does the nullish coalescing operator do?
Q17.
What operator will return the remainder when one operand is divded by another operand?
A) $
B) #
C) %
D) None of the above
Q18.
True or False? getElementsByTagName is a JavaScript function.
A) True
B) False
Q19.
Give an example of when to use event delegation in JavaScript.
Q20.
Does the code below evaluate to true or false?
BigInt(10000000000000000000) === 10000000000000000000
A) true
B) false
Q21.
Which of the following is not a built-in JS error type?
A) Error
B) EvalError
C) SyntaxError
D) TypeError
E) UndefinedError
Q22.
How are numbers stored in JavaScript? Select all that apply.
A) Double precision
B) 64-bit
C) Floating point numbers
Q23.
If a function has no return value specified, what value does it return?
A) null
B) undefined
C) nothing
Q24.
What is the syntax for calling a method which may or may not exist on an object?
Q25.
Which of the following is not a valid Promise method?
A) Promise.some()
B) Promise.allSettled()
C) Promise.reject()
D) Promise.race
Q26.
How can you dynamically access an object property based on a variable value?
Q27.
True or False? A string can be modified after it is created.
A) True
B) False
Q28.
True or False? JavaScript is synchronous.
A) True
B) False
Q29.
True or False? A nested catch in a promise chain can catch errors thrown higher up in the promise chain?
A) True
B) False
Q30.
True or False? The Map object can have keys that are of types other than strings, such as number.
A) True
B) False
Q31.
What will the code below output to the console and why?
const map = new Map();
map.set({},1);
console.log(map.get({}));