Javascript Questions

Warm up for Javascript interview with most asked questions and answers for junior, mid, and senior roles.

Junior

What is NaN property in JavaScript?

Show Answer

NaN property is a property of the global object that is used to represent the Not-a-Number value.

Junior

What is the use of a Number object in JavaScript?

Show Answer

Number object is used to perform number operations.

Junior

What is the use of a Boolean object in JavaScript?

Show Answer

Boolean object is used to perform boolean operations.

Junior

What are the falsy values in JavaScript?

Show Answer

Falsy values are:

  • 0
  • ''
  • null
  • undefined
  • NaN
  • false
Junior

What are JavaScript Data Types?

Show Answer

JavaScript data types are the types of values that JavaScript can store.

 

There are seven data types in JavaScript:

  • Number
  • String
  • Boolean
  • Undefined
  • Null
  • Symbol
  • Object
Junior

What is the use of the Push method in JavaScript?

Show Answer

The push method is used to add an element to the end of an array.

Junior

What is the use of window object?

Show Answer

The window object is a global object that has the properties pertaining to the current DOM document

The document property of the window object has the DOM document and associated nodes and methods that we can use to manipulate the DOM nodes and listen to events for each node.

The window object is global, so it’s available in every part of the application.

Junior

What is JavaScript?

Show Answer

JavaScript is a programming language that allows you to write applications that can run on the client side or server side

Junior

What's the difference between null and undefined?

Show Answer

Undefined is a value that JavaScript assigns to variables that have not been assigned a value.

 

Null is a value that JavaScript assigns to variables that have been assigned a value but that value is null.

Junior

What is === operator?

Show Answer

The === operator is used to compare two values and types. It returns true if both values and types are equal, and false if they are not equal.

Junior

What are all the looping structures in JavaScript?

Show Answer

There are three looping structures in JavaScript:

  • For Loop
  • While Loop
  • Do While Loop
Junior

What is break and continue statements?

Show Answer

Break and continue statements are used to exit a loop or switch statement.

 

Break is used to exit a loop

 

Continue is used to skip the current iteration and continue to the next iteration.

Junior

What boolean operators can be used in JavaScript?

Show Answer

There are three boolean operators in JavaScript:

  • &&
  • ||
  • !
Junior

Explain passed by value and passed by reference.

Show Answer

In Pass by value, function is called by directly passing the value of the variable as an argument. So any changes made inside the function does not affect the original value.

 

In Pass by Reference, Function is called by directly passing the reference/address of the variable as an argument. So changing the value inside the function also change the original value. In JavaScript array and Object follows pass by reference property.

Junior

What are object prototypes?

Show Answer

The prototype is an object that is associated with every functions and objects by default in JavaScript, where function's prototype property is accessible and modifiable and object's prototype property is not visible

Junior

What are callbacks?

Show Answer

A callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

Junior

What is the use of a constructor function in javascript?

Show Answer

A constructor is a special function that creates and initializes an object instance of a class. The purpose of a constructor is to create a new object and set values for any existing object properties.

Junior

What is DOM?

Show Answer

The Document Object Model (DOM) is an API for HTML and XML documents. It is the programming interface for the HTML and XML documents.

Junior

What are arrow functions?

Show Answer

Arrow functions are a new syntactic construct in JavaScript. They are a shorter way to write function expressions.

Mid

What is "this" keyword in JavaScript?

Show Answer

The ‘this’ keyword refers to the object that is currently executing the code. It is used to access properties and methods of an object.

Mid

What is the use of a Set object in JavaScript?

Show Answer

Set object is used to perform set operations.

Mid

What is the difference between strict mode and non-strict mode?

Show Answer

Variables are moved to the top of their scope before code execution

Mid

Name some built-in methods in JavaScript.

Show Answer
  • Date;
  • Math;
  • String;
  • Array.
Mid

Explain Higher Order Functions in javascript.

Show Answer

Higher Order Functions are functions that take other functions as arguments or return other functions.

Mid

What is the Strict Mode in JavaScript?

Show Answer

The strict mode is a way to make JavaScript more strict. It is used to prevent some common mistakes that can lead to JavaScript errors.

Mid

Explain Implicit Type Coercion in javascript.

Show Answer

Implicit type coercion is a process in which a variable is automatically converted to a different type when it is assigned a value.

Mid

Is javascript a statically typed or a dynamically typed language?

Show Answer

JavaScript is a dynamically typed language.

Mid

How to handle exceptions in JavaScript?

Show Answer

You can use try/catch blocks to handle exceptions

 

The try statement allows you to define a block of code to be tested for errors while it is being executed.

 

The catch statement allows you to define a block of code to be executed if an error occurs in the try block.

Mid

Differences between declaring variables using var, let and const.

Show Answer

var

It's hoisted (always declared at top of the scope, global if none) and has function scope.

 

let

It has a block scope and is not redeclarable.

 

const

It has block scope, it's not reassignable and it's not redeclarable.

Mid

What is memoization?

Show Answer

Memoization is an optimization technique used primarily to speed up programs that make repeated calculations.

Mid

What is recursion in a programming language?

Show Answer

Recursion is a technique in which a function calls itself. It is used to solve problems that can be solved by breaking down the problem into simpler sub-problems.

Mid

What is the unshift method in JavaScript?

Show Answer

The unshift method is used to add an element to the beginning of an array.

Mid

Explain Scope and Scope Chain in javascript.

Show Answer

Scope is the visibility of variables and functions.

 

Scope chain is the order in which the variables and functions are searched for a variable or function.

Mid

What is the rest parameter and spread operator?

Show Answer
  • Rest Parameter collects all remaining elements of an array or object into an array.
  • Spread Operator expands collected elements such as arrays or objects into single elements.
  • The spread syntax only does a shallow copy one level deep.
  • Only the last parameter can be a rest parameter.
Mid

What is Promises in javascript?

Show Answer

A Promise represents something that is eventually fulfilled. A Promise can be rejected, resolved or pending based on the operation outcome.

Mid

What is Object Destructuring?

Show Answer

Object destructuring is a JavaScript feature that allows you to extract data from objects into distinct variables.

Mid

List some features of JavaScript.

Show Answer
  • Light Weight Scripting language
  • Dynamic Typing
  • Object-oriented programming support
  • Functional Style
  • Platform Independent
  • Prototype-based
  • Interpreted Language
  • Async Processing
  • Big Community
  • Client-Side Validation
Mid

List some of the disadvantages of JavaScript.

Show Answer
  • Client-Side Security - Since JavaScript code is executed on the client-side, bugs and oversights can sometimes be exploited for malicious purposes. Because of this, some people choose to disable JavaScript entirely.
  • Browser Support - While server-side scripts always produce the same output, different browsers sometimes interpret JavaScript code differently. These days the differences are minimal, and you shouldn't have to worry about it as long as you test your script in all major browsers.
Mid

What is the use of Math object in JavaScript?

Show Answer

Math object is used to perform mathematical operations.

Mid

What is the use of a Date object in JavaScript?

Show Answer

Date object is used to perform date operations.

Mid

Explain Hoisting in javascript.

Show Answer

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution

 

Functions are fully hoisted, but varibles are semi-hoisted.

Senior

Explain WeakSet in javascript.

Show Answer

WeakSet is a collection of objects that are stored using a weak reference. This means that the objects in the set are not directly accessible from outside the set.

Senior

What are Closures?

Show Answer

closure is a stateful function that is returned by another function.

It has access to the parent scope, even after the parent function has closed.

Senior

Explain call(), apply() and, bind() methods.

Show Answer

The call() invokes the function and allows you to pass in arguments one by one.

 

The apply() invokes the function and allows you to pass in arguments as an array.

 

The bind() method creates a new function that, when called, has this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

Senior

What is typeof operator?

Show Answer

Typeof operator is used to check the type of a variable.

Senior

Explain the difference between function declaration and function expression?

Show Answer

Function declarations

  • like vars, they will be automatically hoisted
  • load before any other code

 

Function expressions

  • not hoisted
  • only loads when the interpreter reaches it
Senior

What are generator functions?

Show Answer

Generator functions are functions that can be paused and resumed at any point. They are used to create iterators.

Senior

What is an Immediately Invoked Function in JavaScript?

Show Answer

An Immediately Invoked Function is a function that is automatically invoked when it is defined.

Senior

Explain WeakMap in javascript.

Show Answer

WeakMap is a collection of key-value pairs where the keys are stored using a weak reference. This means that the keys are not directly accessible from outside the map.

Senior

What is the use of a Map object in JavaScript?

Show Answer

Map object is used to perform map operations.

Senior

What is the purpose of setTimeout and setInterval function?

Show Answer

setTimeout and setInterval functions are used to perform asynchronous operations.