JavaScript Interview Questions with answers updated in 2022 for User Interface Developers , Web Designers , Frontend Developers and Web Developers with JavaScript, JS ES6, ES7, ES8, OOPS, AJAX and Web API.


JavaScript

JavaScript or JS is a general purpose programming language used in both frontend and backend. JavaScript is also known as the programming language of web.

JavaScript is lightweight, JIT compiled and high level programming language which follows ECMA International standards. JS has dynamic typing (loosely typed) and is prototype based object-oriented programming language.

JavaScript is among the most popular and used programming language in world with 13.8 Million active developers. It is also the top programming language on Stack Overflow and Github.


What is JavaScript

JavaScript is prototype (object based) based general purpose programming language used in web application and development. JS is also known as the programming language of web. JavaScript was primarily build for web browser only. But now, JavaScript is also used outside a web browser using Node JS.


Is JavaScript Case Sensitive?

Yes, JavaScript is case-sensitive. But HTML and CSS are in case sensitive.


Is JavaScript Compiles or interpreted?

Earlier JS engines Interpreters to executed JS code on runtime. But in 2008, Google Chrome was launched with a modern and better Just In Time (JIT) Compiler. In 2009, Firefox 3.6 also introduced compilation using JIT compiler or runtime compilation to improve JS Execution. Now all modern browsers use JIT Compilation for faster execution of JavaScript.


Variables in javascript

JavaScript Variables are dynamic or loosely typed. A variable can store any type of data, like string, number, boolean, function, array, object etc. Variables are function scoped.

However JS ES6, introduced let and const for block scope. let is used for block scope and is recommended instead of var in modern javascript for mutable data. const is also block scoped with immutable value.


What is variable hoisting?

A variable is declared first and then used. If variable is declared on bottom and used earlier, the value of variable will be undefined. Only assigned values are hoisted in Javascript, like string, numbers etc. Undefined and function declaration can be used before declaration as they are not hoisted, and there is no assignment operator (=) in both.

Variable declaration is hoisted, but variable assignment is not hoisted.


var vs let vs const?

var is used to declare variables in javascript. JavaScript are loosely or dynamic typed and can store any type of data. However JS ES6 introduce let and const for block level scope. let is used to store mutable values, and const is uses to perform immutable values.

Property var let const
hoisting declaration temporal dead zone temporal dead zone
Reinitializeyesnono
reassign valueyesyesno
ScopeFunctionblockblock
Create Global propertyyesnono

What is "use strict" in javascript?

Javascript introduced strict mode in ES5 2009. Strict Mode is recommended for detecting logical errors earlier. Here are the things which are not allowed in strict mode.

<script>
"use strict";
let x=010;                  // octal notation not allowed
y=010;                     // no variable declaration

</script>

What is difference between == and === operator?

== is comparison operator , whereas === is Strict equality. == checks value only, === check value and datatype. For exp

    5=="5"     // true, 
    5==="5"    // false.
    1==true     // true, 
    1===true    // false.
    undefined==null     // true, 
    undefined===null     // false.

What is output of "20" + 20?

"2020". First 20 is string type, second is numeric, for addition, both should be numeric type.


What is output of "20" + 20 + 20 and "20" + ( 20 + 20)?

"20" + 20 + 20 = "202020" but "20" + ( 20 + 20) is "2040".


How to convert "20" to number?

Three ways to convert string into number


let x="20";
x=+x;           //  20
Number(x)       //  20 
parseInt(x)     //  20
parseFloat(x)   //  20
    

What is an AJAX request and give a simple example of where an AJAX request would be used.

AJAX is Asynchronous JavaScript and XML . It is client side process written in Javascript used to get or post data from remote server without reloading page JavaScript AJAX or fetch .


What is Variable Hoisting?

A variable is declared first and then called. If variable is declared on bottom and called earlier, value will be undefined. Only assigned values are hoisted in Javascript, like string, numbers etc. Undefined and function declaration can be called before declaration as they are not hoisted, and there is no assignment operator (=) in both. JavaScript Variables


Callback Function

A function that is passed as argument to another function is called callback function. Callback functions are among High Order Functions. JavaScript Callback Functions.


What is closure in javascript

A var variable declared inside a function, i.e. local variable can also be accessed inside child function. This technique in JavaScript is called closures. See example.


function outer(){
var x=2;            // for both outer and inner functions

function inner(){
    var y=3;        // for inner function only
    var z=x+y;
    return z;        // 5
}
}

Event Delegation, Bubbling and Capturing Events.

Event Propagation are the order that event fire on element. Bubbling is when an event fire on the element and then bubble up DOM Tree. Means First child and then parent will call. Capturing is exactly opposite. First parent node is called and then propagates down towards target element. Event Bubbling Vs capturing


What is Block Scope?

let and const are block scoped in javascript. A curly brackets is a block used in if, for, while etc. let and const can be used only inside block, unlike var (global scope). See more, JavaScript variables


What are Arrow Functions?

Arrow functions are function declaration in es6 but instead of using function keyword, we use ()={}. They are mainly used as callbacks to write better code. Also this keyword is not current object in arrow functions.


let a=(x,y)=>{return x*y} ;
let b=x=>2*x;
[1,3,9,12].sort((a,b)=>a-b);

Popular Tutorial