Javascript Questions
Warm up for Javascript interview with most asked questions and answers for junior, mid, and senior roles.
What is "this" keyword in JavaScript?
Show AnswerHide 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.
What is the use of a Set object in JavaScript?
Show AnswerHide Answer
Set object is used to perform set operations.
What is the difference between strict mode and non-strict mode?
Show AnswerHide Answer
Variables are moved to the top of their scope before code execution
Name some built-in methods in JavaScript.
Show AnswerHide Answer
- Date;
- Math;
- String;
- Array.
Explain Higher Order Functions in javascript.
Show AnswerHide Answer
Higher Order Functions are functions that take other functions as arguments or return other functions.
What is the Strict Mode in JavaScript?
Show AnswerHide 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.
Explain Implicit Type Coercion in javascript.
Show AnswerHide Answer
Implicit type coercion is a process in which a variable is automatically converted to a different type when it is assigned a value.
Is javascript a statically typed or a dynamically typed language?
Show AnswerHide Answer
JavaScript is a dynamically typed language.
How to handle exceptions in JavaScript?
Show AnswerHide 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.
Differences between declaring variables using var, let and const.
Show AnswerHide 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.
What is memoization?
Show AnswerHide Answer
Memoization is an optimization technique used primarily to speed up programs that make repeated calculations.
What is recursion in a programming language?
Show AnswerHide 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.
What is the unshift method in JavaScript?
Show AnswerHide Answer
The unshift method is used to add an element to the beginning of an array.
Explain Scope and Scope Chain in javascript.
Show AnswerHide 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.
What is the rest parameter and spread operator?
Show AnswerHide 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.
What is Promises in javascript?
Show AnswerHide Answer
A Promise represents something that is eventually fulfilled. A Promise can be rejected, resolved or pending based on the operation outcome.
What is Object Destructuring?
Show AnswerHide Answer
Object destructuring is a JavaScript feature that allows you to extract data from objects into distinct variables.
List some features of JavaScript.
Show AnswerHide 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
List some of the disadvantages of JavaScript.
Show AnswerHide 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.
What is the use of Math object in JavaScript?
Show AnswerHide Answer
Math object is used to perform mathematical operations.
What is the use of a Date object in JavaScript?
Show AnswerHide Answer
Date object is used to perform date operations.
Explain Hoisting in javascript.
Show AnswerHide 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.