JavaScript Interview Questions

Today we discuss JavaScript interview questions

  1. What is JavaScript? JavaScript was first known as LiveScropt, but Netscape changed its name to JavaScript. JavaScript is a scripting or programming language. JavaScript can update and change both HTML and CSS and can calculate, manipulate and validate data. JavaScript is mainly used for web-based applications and web browsers.
  2. What are Truthy and Falsy values in JavaScript?

Answer: Truthy and False values are the boolean expressions. Where truthy are expressions that evaluate to a boolean true value and falsy evaluates to boolean false value.

There are only 6 types of falsy values in JavaScript:

  1. false
  2. 0
  3. empty string
  4. null
  5. undefined
  6. NaN

Any expression or value other than the above listed falsy values is considered truthy values.

3. Describe Null and Undefined

Answer: When you declared the value but no value has been assigned to a variable then its output is undefined.

When you assign a value to a variable but if the value is absent at the moment then the output is null.

4. What is the Difference between (==) and (===)?

Answer: Triple equals are used testing for strict value. It will verify whether the variables being compared have both the same value and the same type.

Double equal check for value equality only. Before checking the values, it converts the types of the variables to match each other.


const number = 1234
const string = '1234'
console.log(number == string)
console.log(number === string)

5. What is Scope in JavaScript: Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In the JavaScript language there are two types of scopes:

a. Global Scope

b. Local Scope

6. What is Global Scope?

Variables declared outside of any function become global variables. You can access any variable declared in global scope from other scope.


let a = "hello";function word() {let b = "World" ;console.log(a + b);}word();console.log(a + b); // error

In the above, variable a is a global variable.

7. What is Local Scope?

Variables declared inside function become Local variables. Local variables cannot be accessed outside the function declaration. Local scope is also called function scope because local scope is created by functions in Javascript.


let a = "hello";function word() {let b = "World";console.log(a + b);}word();console.log(a + b); // error

In the above, variable b is a local variable.

8. What is closure in JavaScript?

Closure is one of important concept in JavaScript. a closure gives you access to an outer function’s scope from an inner function.


function outer() {var x = 30;
function inner() {
var y = 10;
return inner;

In the above example,function Inner() can access variable x. Closure can be useful to create private variables or functions.

9. Define Arrow Function

Arrow function is the features of ES6. Arrow function is very simple and shorter than the traditional function.

let A = (x, y) => x * y;

10. Is JavaScript a case-sensitive language?

Yes, JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

The identifiers World and WORLD will convey different meanings in JavaScript.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store