eInterviewQuestions

ECMAScript Interviews Questions

All our users, you can also add/post your question and answer which is mostly asked by an Interviewer in Interviews, you all can suggest for any changes to make our website best & user friendly. please feel free to Post Question.

Q1. What is ECMAScript?

ECMAScript is a language specification standardized byEuropean Computer Manufacturers Association(ECMA).

All major JavaScript implementations adhere to the ECMAScript standard.

ECMAScript Defines

1. Language Syntax – parsing rules, keywords, statements, declarations, operators, etc.

2. Types – boolean, number, string, object, etc.

3. Prototypes and Inheritance

4. Standard Library of built-in objects and functions

ES6

ECMA Script6 or ES6 is the sixth edition of the ECMA script Language specification standard. It is officially referred to as ECMA Script 2015.

TC39, is the committee that drafts the ECMAScript specifications. They follow a yearly model for defining new standards, where new features are added as they are approved, rather than waiting till all features are ready. Thus ES7 will contain all features proposed and approved in 2016.


Q2. What is Block Scope Variables?

Block Scope Variables-

Block is a group of zero or more statements delimited by a pair of curly brackets {}.

Block scope variables are the ones that exist only within the innermost block that surrounds them.

In JavaScript, var is used to create variables. ES6, introduces 2 other keywords for declaring Block scope variables. let & const.

 


Q3. Difference between Let , Var & const ?

Let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.

let doesn't allow properties to be added to the global (window) object.

var x = 10;  

console.log(window.x)     // 10

let x = 10; 

console.log(window.x)    //  undefined

 

const keyword is also used to declare Block Scope variables in ES6. These variables can not be changed once declared unlike let or var.

let x = 10;                                           

x = 20;  // console.log(x) => 20 

const x = 10;

x = 20;  //  Uncaught TypeError: Assignment to constant variable.


Q4. Parameters and Arguments

Parameters (or formal parameters) are given in the function declaration, whereas Arguments (or actual parameters) are passed to the function.

Example:

function foo(a,b) { 

       //do something 

}

foo (10,20);

In this function, a and b are parameters, while 10 and 20 are the arguments.


Q5. What is Spread Parameter?

Spread Operator is used to spread an array elements into parameters.

Example in Javascript

function sum(x, y, z) {

 return x+y+z;

}

let args = [1, 2, 3];

let add = sum.apply(null, args); 

console.log(add);

Example in ES6

function sum(x, y, z) {

 return x+y+z;

}

let args = [1, 2, 3];

let add = sum(...args);

console.log(add);