JavaScript Interview Questions and Answers - 70 JavaScript Interview Questions - DEV Community
JavaScript Interview Questions and Answers - 70 JavaScript Interview Questions - DEV Community
Mark Abeto
Posted on Jan 3, 2020 • Updated on Dec 29, 2022
1840 554 1 4
The Questions
1. What's the difference between undefined and null ?
2. What does the && operator do?
3. What does the || operator do?
4. Is using the + or unary plus operator the fastest way in converting a string to a
number?
5. What is the DOM?
6. What is Event Propagation?
7. What's Event Bubbling?
8. What's Event Capturing?
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 1/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 2/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 3/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
They are falsy values. Values that evaluated to false when converting it to boolean
using Boolean(value) or !!value .
undefined is the default value of a variable that has not been assigned a specific
value. Or a function that has no explicit return value ex. console.log(1) . Or a
property that does not exist in an object. The JavaScript engine does this for us the
assigning of undefined value.
let _thisIsUndefined;
const doNothing = () => {};
const someObj = {
a : "ay",
b : "bee",
c : "si"
};
null is "a value that represents no value". null is value that has been explicitly
defined to a variable. In this example we get a value of null when the fs.readFile
method does not throw an error.
When comparing null and undefined we get true when using == and false when
using === . You can read the reason here.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 4/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Using if statements.
before to initialize default parameter values IN functions before ES6 Default function
parameters was supported.
function logName(name) {
var n = name || "Mark";
console.log(n);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document Object Model</title>
</head>
<body>
<div>
<p>
<span></span>
</p>
<label></label>
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 6/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
<input>
</div>
</body>
</html>
The document object in JavaScript represents the DOM. It provides us many methods
that we can use to selecting elements to update element contents and many more.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 7/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
1. Capturing Phase – the event starts from window then goes down to every element
until it reaches the target element.
2. Target Phase – the event has reached the target element.
3. Bubbling Phase – the event bubbles up from the target element then goes up every
element until it reaches the window .
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 8/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
<div class="grandparent">
<div class="parent">
<div class="child">1</div>
</div>
</div>
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 9/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
});
<div class="grandparent">
<div class="parent">
<div class="child">1</div>
</div>
</div>
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 10/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
});
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 11/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
↑Obviously, this throws an error due to the reason we are trying to access a
x property in the someprop property which have an undefined value. Remember
properties in an object which does not exist in itself and its prototype has a default
value of undefined and undefined has no property x.
Sample JavaScript.
function clickFunc(event) {
console.log(event.target);
}
If you click the button it will log the button markup even though we attach the event
on the outermost div it will always log the button so we can conclude that the
event.target is the element that triggered the event.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 12/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function clickFunc(event) {
console.log(event.currentTarget);
}
If you click the button it will log the outermost div markup even though we click the
button. In this example, we can conclude that the event.currentTarget is the element
on which we attach the event handler.
coercion is the process of converting a value to another type. As in this case, the ==
does implicit coercion. The == has some conditions to perform before comparing the
two values.
1. If x and y have same type. Then compare them with the === operator.
2. If x is null and y is undefined then return true .
3. If x is undefined and y is null then return true .
4. If x is type number and y is type string Then return x == toNumber(y) .
5. If x is type string and y is type number Then return toNumber(x) == y .
6. If x is type boolean Then return toNumber(x) == y .
7. If y is type boolean Then return x == toNumber(y) .
8. If x is either string , symbol or number and y is type object Then return x ==
toPrimitive(y) .
9. If x is either object and x is either string , symbol Then return toPrimitive(x) == y .
10. Return false .
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 13/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Note: toPrimitive uses first the valueOf method then the toString method in objects
to get the primitive value of that object.
x y x == y
5 5 true
1 '1' true
0 false true
The first example goes to condition one because x and y have the same type and
value.
The fifth example goes to condition eight. The array is converted to a string using
the toString() method which returns 1,2 .
The last example goes to condition ten. The object is converted to a string using the
toString() method which returns [object Object] .
x y x === y
5 5 true
1 '1' false
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 14/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
x y x === y
0 false false
If we use the === operator all the comparisons except for the first example will return
false because they don't have the same type while the first example will return true
because the two have the same type and value.
15. Why does it return false when comparing two similar objects
in JavaScript?
↑ Suppose we have an example below.
let a = { a: 1 };
let b = { a: 1 };
let c = a;
console.log(a === b); // logs false even though they have the same property
console.log(a === c); // logs true hmm
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 15/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
let x = 5;
function addFive(num) {
return num + 5;
}
If you log the value of x it would be 27. First, we increment the value of x it would be
6, then we invoke the function addFive(6) and pass the 6 as a parameter and assign
the result to x the new value of x would be 11. After that, we multiply the current
value of x to 2 and assign it to x the updated value of x would be 22. Then, we
subtract the current value of x to 5 and assign the result to x the updated value
would be 17. And lastly, we increment the value of x by 10 and assign the updated
value to x now the value of x would be 27.
Compilation - in this phase it gets all the function declarations and hoists them up to
the top of their scope so we can reference them later and gets all variables declaration
(declare with the var keyword) and also hoists them up and give them a default value
of undefined.
Execution - in this phase it assigns values to the variables hoisted earlier and it
executes or invokes functions (methods in objects).
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 16/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Note: only function declarations and variables declared with the var keyword are
hoisted not function expressions or arrow functions, let and const keywords.
console.log(y);
y = 1;
console.log(y);
console.log(greet("Mark"));
function greet(name){
return 'Hello ' + name + '!';
}
var y;
function greet(name) {
return 'Hello ' + name + '!';
}
for example purposes, I commented on the assignment of variable and function call.
After the compilation phase finishes it starts the execution phase invoking methods and
assigns values to variables.
function greet(name) {
return 'Hello ' + name + '!';
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 17/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
var y;
console.log(y);
y = 1;
console.log(y);
console.log(greet("Mark"));
Global Scope - variables or functions declared in the global namespace are in the
global scope and therefore is accessible everywhere in our code.
//global namespace
var g = "global";
function globalFunc(){
function innerFunc(){
console.log(g); // can access "g" because "g" is a global variable
}
innerFunc();
}
function myFavoriteFunc(a) {
if (true) {
var b = "Hello " + a;
}
return b;
}
myFavoriteFunc("World");
Block Scope - variables ( let , const ) declared within a block {} can only be access
within it.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 18/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function testBlock(){
if(true){
let z = 5;
}
return z;
}
Scope is also a set of rules for finding variables. If a variable does not exist in the
current scope it look ups and searches for a variable in the outer scope and if does
not exist again it looks up again until it reaches the global scope if the variable exists
then we can use it if not it throws an error. It searches for the nearest variable and it
stops searching or looking up once it finds it. This is called Scope Chain.
/* Scope Chain
Inside inner function perspective
//Global Scope
var variable1 = "Comrades";
var variable2 = "Sayonara";
function outer(){
//outer's scope
var variable1 = "World";
function inner(){
//inner's scope
var variable2 = "Hello";
console.log(variable2 + " " + variable1);
}
inner();
}
outer();
// logs Hello World
// because (variable2 = "Hello") and (variable1 = "World") are the nearest
// variables inside inner's scope.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 19/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Closures is simply the ability of a function at the time of declaration to remember the
references of variables and parameters on its current scope, on its parent function
scope, on its parent's parent function scope until it reaches the global scope with the
help of Scope Chain. Basically it is the Scope created when the function was declared.
//Global's Scope
var globalVar = "abc";
function a(){
//testClosures's Scope
console.log(globalVar);
}
In this example, when we declare the a function the Global Scope is part of a's
closure.
The reason for the variable globalVar which does not have a value in the image
because of the reason that the value of that variable can change based on where and
when we invoke the a function.
But in our example above the globalVar variable will have the value of abc.
function outerFunc(outerParam) {
function innerFunc(innerParam) {
console.log(globalVar, outerParam, innerParam);
}
return innerFunc;
}
const x = outerFunc(outerVar);
outerVar = "outer-2";
globalVar = "guess"
x("inner");
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 21/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
This will print "guess outer inner". The explanation for this is that when we invoke the
outerFunc function and assigned the returned value the innerFunc function to the
variable x , the outerParam will have a value of outer even though we assign a new
value outer-2 to the outerVar variable because
the reassignment happened after the invocation of the outer function and in that time
when we invoke the outerFunc function it's look up the value of outerVar in the Scope
Chain, the outerVar will have a value of "outer". Now, when we invoke the x variable
which have a reference to the innerFunc , the
innerParamwill have a value of inner because thats the value we pass in the invocation
and the globalVar variable will have a value of guess because before the invocation of
the x variable we assign a new value to the globalVar and at the time of invocation x
the value of globalVar in the Scope Chain is guess.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 22/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
falsy values are values that when converted to boolean becomes false.
function returnY(){
"use strict";
y = 123;
return y;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 23/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
"use strict";
var NaN = NaN;
var undefined = undefined;
var Infinity = "and beyond";
"use strict";
const obj = {};
Object.defineProperty(obj, 'x', {
value : '1'
});
delete obj.x;
"use strict";
"use strict";
eval("var x = 1;");
"use strict";
function showMeThis(){
return this;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 24/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const carDetails = {
name: "Ford Mustang",
yearBought: 2005,
getName(){
return this.name;
},
isRegistered: true
};
This is what we would normally expect because in the getName method we return
this.name , this in this context refers to the object which is the carDetails object that
is currently the "owner" object of the function executing.
Ok, Let's some add some code to make it weird. Below the console.log statement add
this three lines of code
The second console.log statement prints the word Ford Ranger which is weird
because in our first console.log statement it printed Ford Mustang. The reason to this
is that the getCarName method has a different "owner" object that is the window object.
Declaring variables with the var keyword in the global scope attaches properties in the
windowobject with the same name as the variables. Remember this in the global
scope refers to the window object when "use strict" is not used.
One way of solving this problem is by using the apply and call methods in functions.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 25/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
The apply and call methods expects the first parameter to be an object which would
be value of this inside that function.
IIFE or Immediately Invoked Function Expression, Functions that are declared in the
global scope, Anonymous Functions and Inner functions in methods inside an object
has a default of this which points to the window object.
(function (){
console.log(this);
})(); //logs the "window" object
function iHateThis(){
console.log(this);
}
const myFavoriteObj = {
guessThis(){
function getThis(){
console.log(this);
}
getThis();
},
name: 'Marko Polo',
thisIsAnnoying(callback){
callback();
}
};
If we want to get the value of the name property which is Marko Polo in the
myFavoriteObj object there are two ways to solve this.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 26/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const myFavoriteObj = {
guessThis(){
const self = this; //saves the this value to the "self" variable
function getName(){
console.log(self.name);
}
getName();
},
name: 'Marko Polo',
thisIsAnnoying(callback){
callback();
}
};
In this image we save the value of this which would be the myFavoriteObj object. So
we can access it inside the getName inner function.
const myFavoriteObj = {
guessThis(){
const getName = () => {
//copies the value of "this" outside of this arrow function
console.log(this.name);
}
getName();
},
name: 'Marko Polo',
thisIsAnnoying(callback){
callback();
}
};
Arrow Functions does not have its own this . It copies the value of this of the
enclosing lexical scope or in this example the value of this outside the getName inner
function which would be the myFavoriteObj object. We can also determine the value of
this on how the function is invoked.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 27/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const o = {};
console.log(o.toString()); // logs [object Object]
Even though the o.toString method does not exist in the o object it does not throw
an error instead returns a string [object Object] . When a property does not exist in the
object it looks into its prototype and if it still does not exist it looks into the
prototype's prototype and so on until it finds a property with the same in the
Prototype Chain. The end of the Prototype Chain is null after the Object.prototype.
(function () {
}());
(function () {
})();
(function named(params) {
})();
(() => {
})();
(function (global) {
})(window);
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 28/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
};
})();
These examples are all valid IIFE. The second to the last example shows we can pass
arguments to an IIFE function. The last example shows that we can save the result of
the IIFE to a variable so we can reference it later.
The best use of IIFE is making initialization setup functionalities and to avoid naming
collisions with other variables in the global scope or polluting the global namespace.
Let's have an example.
<script src="https://cdnurl.com/somelibrary.js"></script>
Suppose we have a link to a library somelibrary.js that exposes some global functions
that we use can in our code but this library has two methods that we don't use
and drawGraph because these methods have bugs in them. And we want to
createGraph
implement our own createGraph and drawGraph methods.
<script src="https://cdnurl.com/somelibrary.js"></script>
<script>
function createGraph() {
// createGraph logic here
}
function drawGraph() {
// drawGraph logic here
}
</script>
When we use this solution we are overriding those two methods that the library gives
us.
Another way of solving this is by changing the name of our own helper functions.
<script src="https://cdnurl.com/somelibrary.js"></script>
<script>
function myCreateGraph() {
// createGraph logic here
}
function myDrawGraph() {
// drawGraph logic here
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 29/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
}
</script>
When we use this solution we will also change those function calls to the new function
names.
<script src="https://cdnurl.com/somelibrary.js"></script>
<script>
const graphUtility = (function () {
function createGraph() {
// createGraph logic here
}
function drawGraph() {
// drawGraph logic here
}
return {
createGraph,
drawGraph
}
})();
</script>
In this solution, we are making a utility variable that is the result of IIFE which returns
an object that contains two methods createGraph and drawGraph .
i.So when we click an li element it logs 5 because that is the value of i when we
reference it later in the callback function.
This solution works because of the reason that the IIFE creates a new scope for every
iteration and we capture the value of i and pass it into the currentIndex parameter so
the value of currentIndex is different for every iteration when we invoke the IIFE.
const details = {
message: 'Hello World!'
};
function getMessage(){
return this.message;
}
This method works like Function.prototype.call the only difference is how we pass
arguments. In apply we pass arguments as an array.
const person = {
name: "Marko Polo"
};
function greeting(greetingMessage) {
return `${greetingMessage} ${this.name}`;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 31/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const details = {
message: 'Hello World!'
};
function getMessage(){
return this.message;
}
This method works like Function.prototype.apply the only difference is how we pass
arguments. In call we pass directly the arguments separating them with a comma ,
for every argument.
const person = {
name: "Marko Polo"
};
function greeting(greetingMessage) {
return `${greetingMessage} ${this.name}`;
}
const obj1 = {
result:0
};
const obj2 = {
result:0
};
function reduceAdd(){
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 32/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
let result = 0;
for(let i = 0, len = arguments.length; i < len; i++){
result += arguments[i];
}
this.result = result;
}
handleChange(e){
//do something amazing here
}
render(){
return (
<>
<input type={this.props.type}
value={this.state.value}
onChange={this.handleChange}
/>
>
</>
>
)
}
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 33/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
JavaScript Array has map, filter, reduce methods which are the most famous functions
in the functional programming world because of their usefulness and because they
don't mutate or change the array which makes these functions pure and JavaScript
supports Closures and Higher Order Functions which are a characteristic of a
Functional Programming Language.
The map method creates a new array with the results of calling a provided callback
function on every element in the array.
The filter method creates a new array with all elements that pass the test in the
callback function.
const data = [
{ name: 'Mark', isRegistered: true },
{ name: 'Mary', isRegistered: false },
{ name: 'Mae', isRegistered: true }
];
The reduce method applies a function against an accumulator and each element in
the array (from left to right) to reduce it to a single value.
const strs = ["I", " ", "am", " ", "Iron", " ", "Man"];
const result = strs.reduce((acc, currentStr) => acc + currentStr, "");
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 34/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function higherOrderFunction(param,callback){
return callback(param);
}
The map() method creates a new array with the results of calling a provided
function on every element in the calling array.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 35/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
{
return [];
} else {
let result = [];
// We're making a results array every time we call this function
// because we don't want to mutate the original array.
for (let i = 0, len = arr.length; i < len; i++) {
// check if the return value of the filterCallback is true or "truthy"
if (filterCallback(arr[i], i, arr)) {
// push the current item in the 'result' array if the condition is true
result.push(arr[i]);
}
}
return result; // return the result array
}
}
The filter() method creates a new array with all elements that pass the test
implemented by the provided function.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 36/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
}
}
The reduce() method executes a reducer function (that you provide) on each
element of the array, resulting in a single output value.
We can convert the arguments object into an array using the Array.prototype.slice .
function one() {
return Array.prototype.slice.call(arguments);
}
Note: the arguments object does not work on ES6 arrow functions.
function one() {
return arguments;
}
const two = function () {
return arguments;
}
const three = function three() {
return arguments;
}
When we invoke the function four it throws a ReferenceError: arguments is not defined
error. We can solve this problem if your enviroment supports the rest syntax.
const o1 = {};
console.log(o1.toString());
// logs [object Object] get this method to the Object.prototype
const o2 = Object.create(null);
// the first parameter is the prototype of the object "o2" which in this
// case will be null specifying we don't want any prototype
console.log(o2.toString());
// throws an error o2.toString is not a function
39. Why does b in this code become a global variable when you
call this function?
↑
function myFunc() {
let a = b = 0;
}
myFunc();
The reason for this is that assignment operator or = has right-to-left associativity or
evaluation. What this means is that when multiple assignment operators appear in a
single expression they evaluated from right to left. So our code becomes likes this.
function myFunc() {
let a = (b = 0);
}
myFunc();
First, the expression b = 0 evaluated and in this example b is not declared. So, The JS
Engine makes a global variable b outside this function after that the return value of the
expression b = 0 would be 0 and it's assigned to the new local variable a with a let
keyword.
We can solve this problem by declaring the variables first before assigning them with
value.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 38/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function myFunc() {
let a,b;
a = b = 0;
}
myFunc();
Arrow Functions
Classes
Template Strings
Enhanced Object literals
Object Destructuring
Promises
Generators
Modules
Symbol
Proxies
Sets
Default Function parameters
Rest and Spread
Block Scoping with let and const
42. What's the difference between var , let and const keywords?
↑ Variables declared with var keyword are function scoped.
What this means that variables can be accessed across that function even if we declare
that variable inside a block.
function giveMeX(showX) {
if (showX) {
var x = 5;
}
return x;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 39/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
console.log(giveMeX(false));
console.log(giveMeX(true));
function giveMeX(showX) {
var x; // has a default value of undefined
if (showX) {
x = 5;
}
return x;
}
If you are wondering why it logs undefined in the first console.log statement
remember variables declared without an initial value has a default value of undefined .
Variables declared with let and const keyword are block scoped. What this means that
variable can only be accessed on that block {} on where we declare it.
function giveMeX(showX) {
if (showX) {
let x = 5;
}
return x;
}
function giveMeY(showY) {
if (showY) {
let y = 5;
}
return y;
}
If we call this functions with an argument of false it throws a Reference Error because
we can't access the x and y variables outside that block and those variables are not
hoisted.
There is also a difference between let and const we can assign new values using let
but we can't in const but const are mutable meaning. What this means is if the value
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 40/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
that we assign to a const is an object we can change the values of those properties but
can't reassign a new value to that variable.
//ES5 Version
var getCurrentDate = function (){
return new Date();
}
//ES6 Version
const getCurrentDate = () => new Date();
In this example, in the ES5 Version have function(){} declaration and return keyword
needed to make a function and return a value respectively. In the Arrow Function
version we only need the () parentheses and we don't need a return statement
because Arrow Functions have a implicit return if we have only one expression or
value to return.
//ES5 Version
function greet(name) {
return 'Hello ' + name + '!';
}
//ES6 Version
const greet = (name) => `Hello ${name}`;
const greet2 = name => `Hello ${name}`;
We can also parameters in Arrow functions the same as the function expressions
and function declarations. If we have one parameter in an Arrow Function we can
omit the parentheses it is also valid.
Arrow functions don't have access to the arguments object. So calling the first getArgs
func will throw an Error. Instead we can use the rest parameters to get all the
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 41/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const data = {
result: 0,
nums: [1, 2, 3, 4, 5],
computeResult() {
// "this" here refers to the "data" object
const addAll = () => {
// arrow functions "copies" the "this" value of
// the lexical enclosing function
return this.nums.reduce((total, cur) => total + cur, 0)
};
this.result = addAll();
}
};
Arrow functions don't have their own this value. It captures or gets the this value of
lexically enclosing function or in this example, the addAll function copies the this
value of the computeResult method and if we declare an arrow function in the global
scope the value of this would be the window object.
//ES5 Version
function Person(firstName, lastName, age, address){
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.address = address;
}
Person.self = function(){
return this;
}
Person.prototype.toString = function(){
return "[object Person]";
}
//ES6 Version
class Person {
constructor(firstName, lastName, age, address){
this.lastName = lastName;
this.firstName = firstName;
this.age = age;
this.address = address;
}
static self() {
return this;
}
toString(){
return "[object Person]";
}
getFullName(){
return `${this.firstName} ${this.lastName}`;
}
}
//ES5 Version
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.describe = function () {
return `I am ${this.getFullName()} and I have a position of ${this.jobTitle} and I s
}
Employee.prototype.toString = function () {
return "[object Employee]";
}
//ES6 Version
class Employee extends Person { //Inherits from "Person" class
constructor(firstName, lastName, age, address, jobTitle, yearStarted) {
super(firstName, lastName, age, address);
this.jobTitle = jobTitle;
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 43/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
this.yearStarted = yearStarted;
}
describe() {
return `I am ${this.getFullName()} and I have a position of ${this.jobTitle} and I
}
class Something {
function AnotherSomething(){
}
const as = new AnotherSomething();
const s = new Something();
//ES5 Version
var greet = 'Hi I\'m Mark';
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 44/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
//ES6 Version
let greet = `Hi I'm Mark`;
In the ES5 version, we need to escape the ' using the \ to escape the normal
functionality of that symbol which in this case is to finish that string value. In Template
Literals, we don't need to do that.
//ES5 Version
var lastWords = '\n'
+ ' I \n'
+ ' Am \n'
+ 'Iron Man \n';
//ES6 Version
let lastWords = `
I
Am
Iron Man
`;
In the ES5 version, we need to add this \n to have a new line in our string. In Template
Literals, we don't need to do that.
//ES5 Version
function greet(name) {
return 'Hello ' + name + '!';
}
//ES6 Version
const greet = name => {
return `Hello ${name} !`;
}
In the ES5 version, If we need to add an expression or value in a string we need to use
the + or string concatenation operator. In Template Literals, we can embed an
expression using ${expr} which makes it cleaner than the ES5 version.
const employee = {
firstName: "Marko",
lastName: "Polo",
position: "Software Developer",
yearHired: 2017
};
The old way of getting properties from an object is we make a variable that has the
same name as the object property. This way is a hassle because we're making a new
variable for every property. Imagine we have a big object with lots of properties and
methods using this way in extracting properties will be irritating.
If we use object destructuring it looks cleaner and takes a little time than the old way.
The syntax for object destructuring is that if we are getting properties in an object we
use the {} and inside that, we specify the properties we want to extract and if we are
getting data from an array we use the [] .
We can also have default values when destructuring. In this example, if the firstName
property holds an undefined value in the object then when we destructure the
firstName variable will hold a default of "Mark" .
Modules there were two popular module systems that were used for Code
Maintainability in JavaScript.
CommonJS - Nodejs
AMD (Asynchronous Module Definition) - Browsers
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 47/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
// or
static isUndefined(val) {
return val === undefined;
}
static isNullOrUndefined(val) {
return this.isNull(val) || this.isUndefined(val);
}
}
module.exports = Helpers;
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 48/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
static isUndefined(val) {
return val === undefined;
}
static isNullOrUndefined(val) {
return this.isNull(val) || this.isUndefined(val);
}
}
This is the basics of using ES6 Modules. I won't explain all about Modules because it's
a broad topic and my Post is now really long.
We can make Set instance using Set constructor and we can optionally pass an
Iterable as the initial value.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 49/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
We can add a new value into the Set instance using the add method and since the add
returns the Set object we can chain add calls. If a value already exists in Set object it
will not be added again.
set2.add("f");
set2.add("g").add("h").add("i").add("j").add("k").add("k");
// the last "k" will not be added to the set object because it already exists
We can remove a value from the Set instance using the delete method, this method
returns a boolean indicating true if a value exists in the Set object and false
indicating that value does not exist.
We can check if a specific value exists in the Set instance using the has method.
We can get the length of the Set instance using the size property.
set2.size // returns 10
We can delete or remove all the elements in the Set instance using the clear .
We can use the Set object for removing duplicate elements in an array.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 50/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
In this example, we wait for the click event in the element with an id of btnAdd, if it is
clicked , the clickCallback function is executed. A Callback function adds some
functionality to some data or event. The reduce , filter and map methods in Array
expects a callback as a parameter. A good analogy for a callback is when you call
someone and if they don't answer you leave a message and you expect them to
callback. The act of calling someone or leaving a message is the event or data and
the callback is the action that you expect to occur later.
The problem with this approach if we have another async operation inside the callback
and another. We will have a code that is messy and unreadable. This code is called
Callback Hell.
If we use promises in this code it will be more readable and easy to understand and
easy to maintain.
promReadFile('file/path')
.then(data => {
return promReaddir('directory');
})
.then(data => {
return promMkdir('directory');
})
.catch(e => {
console.log(e);
})
Pending - The initial state of a promise. The promise's outcome has not yet been
known because the operation has not been completed yet.
Fulfilled - The async operation is completed and successful with the resulting value.
Rejected - The async operation has failed and has a reason on why it failed.
The Promise constructor has two parameters which are functions resolve and reject
respectively.
If the async operation has been completed without errors call the resolve function to
resolve the promise or if an error occurred
call the reject function and pass the error or reason to it.
We can access the result of the fulfilled promise using the .then
method and we catch errors in the .catch method. We chain multiple async promise
operations in the .then method because the .then method returns a Promise just like
the example in the imag e above.
myPromiseAsync()
.then(result => {
console.log(result);
})
.catch(reason => {
console.log(reason);
})
We can make a helper func that converts an async operation with a callback to
promise. It works like the promisify utility function from the node core module util .
promReadFile('file/path')
.then((data) => {
console.log(data);
})
.catch(e => console.log(e));
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 53/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
feature because as I said earlier it is built on top of Promises which means is still uses
Promises under the hood.
Using Promises.
function callApi() {
return fetch("url/to/api/endpoint")
.then(resp => resp.json())
.then(data => {
//do something with "data"
}).catch(err => {
//do something with "err"
});
}
Using Async/Await.
Note: We're using the old try/catch statement to catch any errors that happened in
any of those async operations inside the try statement.
Note: The async keyword before the function declaration makes the function return
implicitly a Promise.
giveMeOne()
.then((num) => {
console.log(num); // logs 1
});
Note: The await keyword can only be used inside an async function. Using await
keyword in any other function which is not an async function will throw an error. The
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 54/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
await keyword awaits the right-hand side expression (presumably a Promise) to return
before executing the next line of code.
function getOne() {
try {
const num = await giveMeOne();
console.log(num);
} catch (e) {
console.log(e);
}
}
function add(a, b) {
return a + b;
};
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 55/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
console.log(sum);
In this example, we're using the Spread Operator when we call the add function we
are spreading the nums array. So the value of parameter a will be 5 and the value of b
will be 6. So the sum will be 11.
function add(...rest) {
return rest.reduce((total,current) => total + current);
};
In this example, we have a function add that accepts any number of arguments and
adds them all and return the total.
In this another example, we are using the Rest operator to extract all the remaining
array values and put them in array others except the first item.
//ES5 Version
function add(a,b){
a = a || 0;
b = b || 0;
return a + b;
}
//ES6 Version
function add(a = 0, b = 0){
return a + b;
}
//If we don't pass any argument for 'a' or 'b' then
// it's gonna use the "default parameter" value which is 0
add(1); // returns 1
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 56/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
getFirst(); // returns 0
getFirst([10,20,30]); // returns 10
We can also use the parameters defined first to the parameters defined after them.
name is a primitive string value that has no properties and methods but in this
example we are calling a toUpperCase() method which does not throw an error but
returns MARKO .
The reason for this is that the primitive value is temporarily converted or coerce to an
object so the name variable behaves like an object . Every primitive except null and
undefined have Wrapper Objects. The Wrapper Objects are
String , Number , Boolean , Symbol and BigInt . In this case, the name.toUpperCase()
invocation, behind the scenes it looks like this.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 57/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
console.log(1 + '6');
console.log(false + true);
console.log(6 * '2');
The first console.log statement logs 16 . In other languages this would throw a
compile time error but in JavaScript the 1 is converted to a string then concatenated
with the + operator. We did not do anything, yet it was converted automatically by
JavaScript for us.
The second console.log statement logs 1, it converts the false to a boolean which
will result to a 0 and the true will be 1 hence the result is 1.
The third console.log statement logs 12 , it converts the '2' to a number before
multiplying 6 * 2 hence the result 12 .
JavaScript Coercion Rules
While Explicit Coercion is the way of converting values to another type where we
(programmers) explicitly do it.
console.log(1 + parseInt('6'));
In this example, we use the parseInt function to convert the '6' to a number then
adding the 1 and 6 using the + operator.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 58/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
let a;
console.log(parseInt('abc'));
console.log(parseInt(null));
console.log(parseInt(undefined));
console.log(parseInt(++a));
console.log(parseInt({} * 10));
console.log(parseInt('abc' - 2));
console.log(parseInt(0 / 0));
console.log(parseInt('10a' * 10));
JavaScript has a built-in method isNaN that tests if value is isNaN value. But this
function has a weird behaviour.
All these console.log statements return true even though those values we pass are
not NaN .
function checkIfNaN(value) {
return value !== value;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 59/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
If your environment does not support this method you can use the polyfill
implementation.
function isArray(value){
return Object.prototype.toString.call(value) === "[object Array]"
}
function isEven(num) {
if (num & 1) {
return false;
} else {
return true;
}
};
0 in binary is 000.
1 in binary is 001.
2 in binary is 010.
3 in binary is 011.
4 in binary is 100.
5 in binary is 101.
6 in binary is 110.
7 in binary is 111.
and so on...
a b a & b
0 0 0
0 1 0
1 0 0
1 1 1
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 60/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
So when we console.log this expression 5 & 1 it returns 1. Ok, first the & operator
converts both numbers to binary so 5 turns to 101 and 1 turns to 001.
Then it compares every bit (0's and 1's) using the bitwise AND operator. 101 & 001.
As we can see from the table the result can be only 1 if a AND b are 1 .
101
001
001
So first we compare the left most bit 1 & 0 the result should be 0.
Then we compare the middle bit 0 & 0 the result should be 0.
Then we compare the last bit 1 & 1 the result should be 1 .
Then the binary result 001 will be converted to a decimal number which will be 1.
If we console.log this expression 4 & 1 it will return 0. Knowing the last bit of 4 is 0
and 0 & 1 will be 0 . If you have a hard time understand this we could use a recursive
function to solve this problem.
function isEven(num) {
if (num < 0 || num === 1) return false;
if (num == 0) return true;
return isEven(num - 2);
}
First , using the in operator. The syntax for using the in operator is like this
propertyname in object . It returns true if the property exists otherwise it returns false .
const o = {
"prop" : "bwahahah",
"prop2" : "hweasa"
};
console.log("prop" in o); //This logs true indicating the property "prop" is in "o" ob
console.log("prop1" in o); //This logs false indicating the property "prop" is not in
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 61/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Second, using the hasOwnProperty method in objects. This method is available on all
objects in JavaScript. It returns true if the property exists otherwise it returns false .
Third, using the bracket notation obj["prop"] . If the property exists it returns the value
of that property otherwise this will return undefined .
const o = {
name: "Mark",
greeting() {
return `Hi, I'm ${this.name}`;
}
};
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 62/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function Person(name) {
this.name = name;
}
Person.prototype.greeting = function () {
return `Hi, I'm ${this.name}`;
}
const n = {
greeting() {
return `Hi, I'm ${this.name}`;
}
};
o.name = "Mark";
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 63/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Callbacks
Promises
async/await
Libraries like async.js, bluebird, q, co
hoistedFunc();
notHoistedFunc();
function hoistedFunc(){
console.log("I am hoisted");
}
The notHoistedFunc call throws an error while the hoistedFunc call does not because the
hoistedFunc is hoisted while the notHoistedFunc is not.
Read Hoisting here.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 64/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
//Global Scope
function add(a,b){
console.log(this);
return a + b;
}
const o = {
method(callback){
callback();
}
}
o.method(function (){
console.log(this); // logs the "window" object
});
const details = {
name : "Marko",
getName(){
return this.name;
}
}
this.name = name;
this.position = position;
this.yearHired = yearHired;
// inherits from Employee.prototype
// returns the "this" value implicitly if no
// explicit return statement is specified
};
Invocation with the apply and call methods - If we want to explicitly specify the
this value or the "owner" object of a function we can use these methods. These
methods are available for all functions.
const obj1 = {
result:0
};
const obj2 = {
result:0
};
function reduceAdd(){
let result = 0;
for(let i = 0, len = arguments.length; i < len; i++){
result += arguments[i];
}
this.result = result;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 66/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
function memoize(fn) {
const cache = {};
return function (param) {
if (cache[param]) {
console.log('cached');
return cache[param];
} else {
let result = fn(param);
cache[param] = result;
console.log(`not cached`);
return result;
}
}
}
toUpperMemoized("abcdef");
toUpperMemoized("abcdef");
This memoize helper function only works on a function that accepts one argument. We
need to make a memoize helper function that accepts multiple arguments.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 67/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
memoizedMakeFullName("Marko", "Polo");
memoizedMakeFullName("Marko", "Polo");
69. Why does typeof null return object ? How to check if a value
is null ?
↑ typeof null == 'object' will always return true because this was the implementation
of null since the birth of JavaScript. A fix was proposed to change typeof null ==
'object' to typeof null == 'null' but was rejected because it will lead to more bugs
to existing projects and softwares.
We can use the === or strict equality operator to check if a value is null .
function isNull(value){
return value === null;
}
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 68/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
It's funny how interviews often focus on memorization these kind of things, which are the
easiest things to look up when you need them.
Half of these things i encountered and used without' having to know the right name for
what i was doing, so whats the value?
Comparatively speaking, having those kinds of discussions seem much more relevant
than whether or not i have memorized all the latest programmer pop culture and
random terms one might use once every blue moon.
This is a nice list to memorize if you wanna play the default interview game.
Which i might in the future, so thanks! :)
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 69/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
I feel you man but most of the time memorizing or knowing this things are not about
answering an Interview problem or problems but solving a problem you are having
with JavaScript and btw Glad you like it!!!
If I was asked any of these at a job interview, I couldn't answer a single one 👍
Thanks Kiss 😁
Regarding Question 24, I want to really understand "this" so I tested each example in the
Console. I found a different result than what you shared for this line...
myFavoriteObj.guessThis();
You wrote that it logs the window object; however, I'm seeing that in normal mode it
logs nothing and in strict mode it throws an error. Maybe it is working differently on your
browser? I'm using Chrome 81 on Mac.
Thanks, for finding my mistake. I edited it just now. No problem man, glad you like it.
Believe it or not, I'm still going through your list and taking notes. This is a very cool
post.
By the way, I've cleared my browser cache the graphic is the same. Maybe it's cached
on the server side?
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 70/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
const myFavoriteObj = {
guessThis(){
function getThis(){
console.log(this);
}
getThis();
},
name: 'Marko Polo',
thisIsAnnoying(callback){
callback();
}
};
Thanks
Ah, I see the change now. You removed .name from where it used to say
console.log(this.name); Thank you!
rather than
var name = "Ford Ranger";
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 71/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Nice work! Most of these are pretty good. If you're a hiring manager reading this though,
I'd caution against asking questions like "is using the + or unary plus operator the fastest
way in converting a string to a number?" because it really doesn't matter and you
shouldn't make hiring decisions based on one's knowledge of that.
Great set of questions :) I want to clarify one thing though: "What does the && operator
do?" - It does not return last "truthy" or "falsy" value. It returns the last value it has to
calculate to determine the truthiness of the whole expression, eg. 0 || 0 || 0 - will
return 0 and 1 && 1 && 1 - will return 1 . So the statement in the article is not 100%
accurate :) Can't wait to see the update ;)
G.O.A.T
Great !
Personally, I think that good interviews should be focused on data flows and
performance optimization, and asking about certain API's should be only for choosing
the right question as an interviewer.
Also, interviewers should understand the difference between someone who is not
knowing something, to someone who is not capable of learning something new.
Hi! Many thanks for the article, it's really very useful)))
And one thing in Question 31:
const result = strs.reduce((acc, currentStr) => acc + str, "");
I suppose you mean "currentStr" instead of "str" ;)
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 72/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Mark, you did a grate job. I am finding this list very useful. In a way, it even helped me to
make the list of questions for our small organisation(I have even sent it to some of our
HRs))) So, believe it or not ..It is used now in practical way in the eastern EU))))If being
completely serious, I would recommend more Typescript questions. I know this is the
JavaScript Int. Q. I really thing < that using of typescript is growing tremendously.
Anyway , great Job, Mark. Thank you.
Hi Alecc, I'm really glad that you like it. That's a nice suggestion. I've been using
typescript for over two years now and it's really great it makes your JavaScript code
more readable and maintainable. I'll make some questions in the future. Thanks and
God bless.
Yes,m Mark, that is amazing how fast the Typescript "cases" grow. I mean , two years
ago I have the project, where I had one TS file and I do not even remember why. But
now. My team just received a source , There were no JS file extension. TS, TSx). I am,
actually, just starting with Typescript.
“let x = 5;
function addFive(num) {
return num + 5;
}
If you log the value of x it would be 27. First, we increment the value of x it would be 6,
then we invoke the function incrementBy5(6) and pass the 6 as a parameter”
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 73/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Also,
Thanks again 😁
Great article. Very informative. For the question 34, 35 and 36. The implementation might
not be quite accurate. You might wanna re-check. For example, to map(), we just pass the
callbackfunction. While in your implementation above, you are passing both array and
callback to the map(). The array will be available as this inside the map(). Please do
correct me if i am wrong.
I think this is the longest read time I ever see on the internet. Thank you for the article.
I'd bookmark for future references.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 74/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
actually Implement the Array.prototype.map is not too precise for what really wanted to
be implemented.
[,1,2,3,].map(console.log)
// [empty, undefined, undefined, undefined]
map([,1,2,3,], console.log)
// [undefined, undefined, undefined, undefined]
Great content! My name is Kairat, I'm a freelance self tough js developer. I'm planning to
get a job as a Front end developer instead of freelancing.
Question: This article is very helpful for my theoretical knowledge. I'm just curious will I
use these terms in my daily job? Seems like preparation for the exam and I will not use
this knowledge in work. Or use very rarely.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.
DEV Community
Trending in Career
The Career community is currently focused on the challenges of web development,
balancing passion projects with paying work, the importance of community
mentorship, and AWS certification strategies.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 75/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Mark Abeto
a Full-Stack developer who likes reading Tom Clancy's books and loves talking with dogs.
LOCATION
Cebu City
EDUCATION
Bachelor's Degree in Computer Engineering
WORK
Integration Engineer
JOINED
Jul 25, 2019
How to configure Webpack with React Testing Library from the ground up
#testing #react #tutorial #webdev
MongoDB PROMOTED
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 77/78
8/19/23, 11:08 AM JavaScript Interview Questions and Answers: 70 JavaScript Interview Questions - DEV Community
Stay ahead of the competition. Get access to the latest database features and adapt to changing
trends with MongoDB Atlas.
https://dev.to/macmacky/70-javascript-interview-questions-5gfi 78/78