Javascript Interview Questions
Javascript Interview Questions

Javascript Interview Questions

(1)hosting: In JavaScript, a variable can be declared after it has been used. In other words; a variable can be used before it has been declared.To understand this, you have to understand the term “hoisting”. Hoisting is JavaScript’s default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).

ES5 & Functions: ECMAScript 2009, also known as ES5, was the first major revision to JavaScript.

(i) trim(): String.trim() removes whitespace from both sides of a string.
example: var String=” Siddhartha”;
String.trim();

(ii) Array.isArray(): The isArray() method checks whether an object is an array.
example: var Lang=[“php”,”java”,”cobol”];
Array.isArray(Lang);

(iii) Array.forEach(): The forEach() method calls a function once for each array element. example: var Lang=[“php”,”java”,”cobol”];
Lang.forEach(returnArrayVal);
function returnArrayVal(Arrvalue){
return Arrvalue;
}

(iv)Array.map(): This function send each element of array in user defined function

(v)Array.reduce(): This function used to find the sum of array

(v)Array.reduceRight(): This function used to find the sum of array

(vi)Array.indexOf(): Search an array for an element value and returns its position.

(vii)Array.lastIndexOf(): Array.lastIndexOf() is the same as Array.indexOf(), but searches from the end of the array.

(viii)JSON.parse(): JSON. parse() takes a JSON string and transforms it into a JavaScript object.

(ix) JSON.stringify(): JSON.stringify() takes a JavaScript object and transforms it into a JSON string.

New Features in ECMAScript 2016

i) Class class object concept in ES6

ii) JavaScript Exponentiation (**): The exponentiation operator (**) raises the first operand to the power of the second operand.
let x = 5;
let z = x ** 2; // result is 25

iii) for/of Loop:The JavaScript for/of statement loops through the values of an iterable objects. example:var arrStu=[“Java”,”Php”,”Cobol”];
for(arrStu of arrStu){
alert(arrStu);
}

iv) Default Parameter Values: ES6 allows function parameters to have default values. example:function createMuptiplication(r,t=10){
alert(r*t);
}
createMuptiplication(6)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *