Prev Next

Web / ES6 Interview questions

Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. Difference between Named Exports and Default exports in ES6.

Named Exports can export multiple values and must use the exported name when importing.

Default Exports export a single value and can use any name when importing.

2. What is ES6 or ECMAScript 2015?

ES6 was released in June 2015 as the sixth edition of the language. Initially, it was named ES6 and later renamed to ECMAScript 2015. This edition includes several new features such as modules, iterators, class, arrow functions, for...of loop, promises, and many more. Brendan Eich developed it.

3. What is ECMAScript?

ECMAScript is a specification that is defined in the ECMA-262 standard to create a general-purpose scripting language.

4. Explain let and const keywords.

The variables declared using let keyword will be mutable and the values can be changed at anytime. It is similar to var keyword except that it provides block scoping.

The variables declared using the const keyword are immutable and block-scoped. The value of the variables cannot be changed or re-assigned.

5. Explain arrow function in ES6.

Arrow functions are the shorthand notation to write ES6 functions. The definition of the arrow function consists of parameters, followed by an arrow (=>) and the body of the function.

An Arrow function is also known as 'fat arrow' function. We cannot use them as constructors.

const functionName = (arg1, arg2) => {  
    //body of the function  
}  
6. Difference between const vs Object.freeze().

const applies to bindings ("variables"). It creates an immutable binding, i.e., you cannot assign a new value to the binding.

Object.freeze works on values, and more specifically, object values. It makes an object immutable, i.e., you cannot change its properties.

7. What is Promise.race()?

The Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise.

const promise1 = new Promise((resolve, reject) => {
  setTimeout(resolve, 500, 'one');
});

const promise2 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'two');
});

Promise.race([promise1, promise2]).then((value) => {
  console.log(value);
  // Both resolve, but promise2 is faster
});
// expected output: "two"

«
»
ES8 Interview questions

Comments & Discussions