Professional Documents
Culture Documents
Member-only story
-- 4
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40fu…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 1 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
I am going to start a series for the JavaScript interview questions which may
help junior to mid level developers.
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 2 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
Example:
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 3 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
Example:
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 4 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
Example:
function sum(...args) {
return args.reduce((a, b) => a + b);
}
console.log(sum(1, 2, 3, 4, 5));
// Output: 15
var is function scoped and its value can be changed, while let and const
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 5 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
are block scoped and their values cannot be changed once they are assigned
with const .
Example:
A closure is a function that has access to variables in its outer scope, even
after the outer function has returned.
Example:
function outerFunction(counter) {
return function innerFunction() {
return ++counter;
};
}
let counter = 0;
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 6 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
promise.then(result => {
console.log(result); // Output: "Hello, World!"
});
async/await is a way to write asynchronous code that looks and behaves like
synchronous code.
Example:
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40fu…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 7 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
A class is a blueprint for creating objects that defines a set of properties and
methods.
Example:
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 8 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, my name is ${this.name} and I am ${this.age} years old.`;
}
}
let person = new Person("John", 30);
console.log(person.greet()); // Output: "Hello, my name is John and I am 30 years old
Example:
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, my name is ${this.name} and I am ${this.age} years old.`;
}
}
let person = new Person("John", 30);
console.log(person.greet()); // Output: "Hello, my name is John and I am 30 years old
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 9 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
undefined means a variable has been declared but has not been assigned a
value, while null is explicitly set to represent no value.
Example:
let name;
console.log(name === undefined); // Output: true
let city = null;
console.log(city === null); // Output: true
16. What is the difference between let and const when declaring a constant?
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 10 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Both let and const can be used to declare a constant, but the value of a
const cannot be changed after it is declared, while the value of a let can be
changed.
Example:
const PI = 3.14;
// PI = 3.15;
console.log(PI); // Output: 3.14
let name = "John";
name = "Jane";
console.log(name); // Output: "Jane"
Example:
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 11 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
function sum(...numbers) {
return numbers.reduce((total, num) => total + num, 0);
}
console.log(sum(1, 2, 3)); // Output: 6
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 12 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Example:
function multiplyBy(factor) {
return function (number) {
return number * factor;
};
}
let double = multiplyBy(2);
console.log(double(5)); // Output: 10
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 13 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
Learn Javascript
444 Followers
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 14 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
FullStackTips FullStackTips
-- 2 --
FullStackTips FullStackTips
-- --
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 15 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
-- 2 -- 13
Lists
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 16 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
-- -- 2
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 17 of 18
"Top 25 JavaScript Interview Questions and Answers for 5 Years of Experience (ES6 and Above) | Medium 6/23/23, 6:39 PM
-- -- 7
Help Status Writers Blog Careers Privacy Terms About Text to speech Teams
https://12ft.io/api/proxy?ref=&q=https%3A%2F%2Fmedium.com%2F%40f…20-javascript-interview-questions-with-code-answers-dd9fb28f3f5a Page 18 of 18