50+ JavaScript interview questions and answers for freshers

javascript interview questions pdf, 
javascript interview questions for fresher,
javascript interview questions and answers,
javascript interview questions and answers for experience,
javascript interview questions github, 
javascript interview questions and answers 2022,
Interview questions on JavaScript for freshers

These are the 50 most important javascript interview questions and answers for freshers and 2 year experience. We are trying to put javascript interview questions pdf download link for the same JS interview questions with more advanced stuff. Also check interview questions for JavaScript’s popular framework like react js and Angular JS.

Q.1. What is Javascript?

js interview questions and answers for experienced,
js interview questions and answers for freshers,
js interview questions for freshers, 
js interview questions advanced,
js interview questions for experienced professionals,
interview questions on javascript programming

Javascript is basically scripting language used to make web pages more interactive. It can be used along with HTML and CSS.

Q.2. What are features of Javascript?

Javascript allows you to validate user input before sending it to server for backend operations called Input validation. It provides you Control over browser due to which you can change the background colour of this page as well as the text on the browser’s status bar. It can detect user’s browser and OS due to which you can perform platform dependant operations.
Handling date and time : Javascript enables you to write code based users date and time, it also enables you to capture users date and time as user and server may be in different time zone. Javascript enables you to dynamically generate HTML.

Q.3. What are advantages of Javascript?

JavaScript is fast because it run immediately within the client-side browser. Javascript is not dependant on network unless backend data is required to be processed. No Need to compile Javascript on the client–side as it is interpreted directly by web browsers.

  • Interoperability : Javascript can be inserted into web page regardless of extension. JS can be used within other languages such as Perl and PHP inside the script.
  • Rich interfaces : Javascript has vast libraries like (charts, drag and drop, sliders etc.) which enables you to provide attractive look to your website.
  • Reduction in server load : Since Javascript is client-side scripting language it reduces load on website servers as many operations can be performed at client’s machine which reduces load on server and enables it serve to more users.

Q.4. What are disadvantages of Javascript?

Major disadvantages of JS are:

  • Client-side security : JavaScript code executes in users computer hence in some cases it can be manipulated for malicious purpose.
  • Browser support : JavaScript is sometimes interpreted differently by different browsers.

Q.5. What is difference between Javascript and ECMAScript?


JavaScript is a scripting language that has been formed by keeping ECMAScript specification at its core. ECMAScript is nothing but a standard or specification defined in order to create different scripting languages and one of them is JavaScript. Javascript, Jscript and ActionScript are few scripting languages that follow ECMAScript specifications.

Q.6. Who developed Javascript?

JavaScript was created in 1995 by Brendan Eich during his time at Netscape Communications. It was inspired by Java, Scheme and Self.

Q.8. What are advantages of using external javaScript?

Placing JavaScript code in external .js files has few advantages over inline scripts:

  • Segregating HTML and JavaScript code helps to manage the code base better.
  • To improve development output designers can work along with coders in parallel without code conflicts.
  • This approach also works well with modern source code version control systems like GIT and SVN.
  • Each of these files can maintain history.
  • Segregating HTML and JavaScript makes it more readable.
  • Segregated external JavaScript files are cached by browsers and can speed up page load times
  • These small js files can be minified to reduce the size and make it not readable by humans, using Google closure or YUI Compressoror other.
  • Many popular JavaScript libraries are available as hosted on content delivery networks (cdn) and you can simply point to them using the URL in the src, this avoids copying the js file to local folder.
  • Using external Js you can take benifits of advanced tools such as RequireJS or CommonJS to load these scripts logically and modularly

Q.9. Javascript is case sensitive language?

Yes, Javascript is case sensitive scripting language. Variables, functions, keywords must have consistent casing otherwise it will not be recognized by Javascript and will generate error.
​ var pratik;
​ var praTik;
In above case pratik and praTik will be considered as different variables.

Q.10. Is Semicolon compulsory in Javascript at end of the statement?

No, it is not necessary to use semicolon at end of the statement still it will be considered as valid statement. But, using semicolon at the end of statement in JS is considered as a good coding practice.

Q.11. What are different data types in Javascript?

interview questions and answers on javascript,
interview questions on javascript,
interview questions on javascript for freshers,
interview questions on javascript for 3 years experience,
interview questions on js, 
interview questions on js for freshers,
js interview questions and answers for experienced

JavaScript data types are broadly classified as Primitive and Non-Primitive:

Primitive Data Types:

  • Number: Represent numeric values, both integer and float.
  • String: Sequence of characters are represented using String.
  • Boolean: Represent Boolean value, true or false.
  • Undefined: Represent undefined value.
  • Null: Represent null.

Non-Primitive Data Types:

  • Object: Represent more complex data structure.
  • Array: Represent group of elements.
  • RegExp: Represent regular expression.

Q.12. How to add comment?


JavaScript provides two kinds of comments:
Single-line comments and multiline comments.
Single-line comments start with // and are terminated by the end of the line:
​ x++; // single-line comment
Multiline comments are delimited by /* and */:
​ /* This is
​ a multiline
​ comment.
​ */

Q.13. What is Javascript engine?

JavaScript engine is a computer program used to execute Javascript code. JS engines were developed by web browser vendors and every major browser has one.

Chrome V8 from google is most used engine, Google chrome use it.
SpiderMonkey is developed by Mozilla for use in firefox.
JavaScriptCore is Apples engine for its Safari browser.

Q.14. List the different JavaScript frameworks that you know?

Many frameworks are based on JavaScript, some of them are listed below:


From the above JS frameworks Angular, React, Vue and Node.js are some of the most popular JavaScript frameworks. These 4 are the highly used ones and have large community support.

15. Explain variable in Javascript.

Basically, variable is used for temporary storage of data. It has name, value and memory address. You have to declare variable before using it for storing data. Below is syntax to declare variable:
var variablename;
Here var is keyword and variablename is name of the variable.
You can also define multiple variables using single statement as:
var variable1, variable2, variable3;
Value can be assigned to variable as:
var variablename = value;


Q.16. What is var?

The var statement declares a variable and can also optionally initialize its value.

Q.17. What is let?

The ‘let’ allows you to declare variables that are limited in scope to the particular block, expression on which it is used or statement.

Q.18. What is const?

Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can’t be re-declared. It remains constant throughout the execution

Q.19. What is difference between let and var?

The variable defined with var is available anywhere within the function hence ’var’ keyword has function scope.
The let has a Block Scope. A variable declared with ‘let’ keyword has a scope only with in that block.

Q.20. What is difference between let and const?

‘let’ allows you change the value of variable any number of times.
Using ‘const’, after the first assignment of the value we cannot redefine the value or update it.


Q.21. What is automatic type conversion?

When JavaScript tries to operate on a wrong date type it will try to convert the value to a “right” type.

Q.22. What are operators in Javascript?

An operator is a symbol or word which is used to perform particular operation. Arithmetic, Assignment, Comparison, Logical and Conditional Operators are types of operators.

Q.24. What are control flow statements?

You can change the sequence in which Javascript statements are executed by using control flow statements.
Below are types of control flow statements:
Selection statements : Selection statements use condition to determine which group of statements should be executed, if….else, if and switch are selection statements.
Loops : Loops allow you to execute group of statements repeatedly till condition is satisfied, while, do…while and for are loops.
Jump statements : Jump statements are used to break or exit loop, break and continue are jump statements.


Q.25. What is break statement in JavaScript?

Break statement stops execution of loop entirely and jumps out of the present loop.

Q.26. What is continue statement in JavaScript?

Continue statement stops execution of current iteration in a loop and continues with next iteration of loop.

Q.27. What is the difference between comparing variables using “==” and “===” operator?


The ‘==’ operator tests for abstract equality i.e. it does the required type conversions before doing the equality comparison.
But the ‘===’ operator tests for strict equality i.e. it will not do the type conversion thus if the two values are not of the same type, when compared, it will return false.

Q.28. What is typeof operator?

The typeof operator is used to get the data type of its operand. The operand can be either a literal or a data structure such as variable, function or an object.
console.log(typeof somevar);
The typeof operator returns below values as string: object, Boolean, function, number, string and undefined.

Q.29. What is variable hoisting?


In Javascript regardless of where the actual declaration has been made, all variable declarations that are using var, are hoisted/lifted to the top of their functional/local scope (if declared inside a function) or to the top of their global scope (if declared outside of a function). This lifting of scopes is called hoisting.
​ bla = 2;
​ var bla;
​ // …is implicitly understood as:
​ var bla;
​ bla = 2;

Q.30. What is difference between undefined and null?

The undefined means a variable has been declared but has no value has yet been assigned. On the other hand, null is basically a value which has been assigned. Also, undefined is a type itself (undefined) while null is an object. Unassigned variables are initialized with a default value of undefined by JavaScript or undefined can be assigned to variable through code. Whereas JavaScript never sets a value to null by default. That must be set programmatically.

Q.31. What is output of null == undefined?

null == undefined will return true .
However, null === undefined will return false .

Q.32. What are escape characters?


Escape characters (backslash) is used before special characters like ampersand, single quotes, double quotes and apostrophes to display them.
console.log(‘I\’m Pratik Bandal’); ☐ Correct syntax
console.log(‘I’m Pratik Bandal’); ☐ Incorrect syntax
In above example, if backslash is not used before single quotes this line will give syntax error.

Q.33. How to create array in javascript?

You can define arrays using the array literal as follows-
var a = [];
var b = [1, 2, 3];

Q.34. How to create three dimensional array?

You can define three dimentionalarray arrays using the array follows:
var threedimentionalarray = [[[]]];

Q.35. What are the variable naming conventions in JavaScript?

The following rules are to be followed while naming variables in JavaScript:
You are not allowed to use any of the reserved keyword as variable name.
JavaScript variable names should not begin with a numbers (0-9).
They must start with a letter or the underscore character.
JavaScript variable names are case sensitive.

Q.36. Why you should not prefer to use global variables?

Global variable can be created by many developers resulting in duplicate global variables. Duplicate variable can overwrite the value of your variable.

Q.37. What are functions?

Function is a collection of statements which can be used anywhere in program, it is used to perform specific task.

Q.38. What are types of functions in Javascript?


Below are the types of functions:
Named: Functions which have name at the time of definition are named functions.
function print() {
​ console.log(“This is named function!!!”);
Anonymous: Functions which do not have names are anonymous functions.
var print=function() {
​ console.log(“This is anonymous function!!!”);

Q.39. What are frequently used built-in global functions?

Alert(), prompt(), isNan(), eval(), isFinite(), confirm(), parseInt(), parseFloat(), escape(), unescape() are most frequently used built-in global functions.

Q.40. What is isNaN?


It is a function which determine whether or not value is an illegal number. The isNan() method returns true if the passed value is NaN(Not a number) and is of type number, else it returns false.
Input: ‘213’
Output: false
Output: true

Q.41. What is parseInt?

The parseInt() is a function which parses the string and returns the integer value found in string.

Q.42. What is alert?

The alert() function is used to display information in message box.

Q.43. What is confirm?

The confirm() function displays a message box with two buttons, Ok and cancel. When you click the Ok button, the function returns true. When you click cancel button function returns false.

Q.44. What is charAt?

The charAt() function returns character from specified index.
​ ​ var str=”Pratik”;
​ ​ console.log(str.charAt(0));
​ ​ Output :
​ ​ P


Q.45. What is indexOf?

This function returns the index within the calling string object of first occurrence of the specified value and returns index of found occurrence or -1 if not found.
​ ​ var str=”This is javascript book”;
​ ​ console.log(str .indexOf(“javascript”));
​ ​ Output:
​ ​ 8

Q.46. What are function scopes?

Scope defines accessibility of function and its variables. In Javascript scope is divided into two categories:
Global : Function with global scope can be accessed anywhere in the program.
Local : Function with local scope can be accessed only within its parent function.

Q.47. What is strict mode?


Strict mode prevents certain actions and throws more exceptions. The statement “use strict” orders browser to use the Strict mode, which is a reduced and safer feature set of JavaScript. Strict mode eliminates some silent errors in JavaScript by changing them to throw errors. Strict mode resolves mistakes that make it difficult for JavaScript engines to perform optimizations hence strict mode code can sometimes run faster than identical code that’s not strict mode.

Strict mode forbids some syntax likely to be defined in future versions of ECMAScript. It prevents, or throws errors, when unsafe actions are taken (such as gaining access to the global object). It disables features that are confusing or poorly thought out.

Due to Strict mode it becomes easier to write secure JavaScript. Strict mode applies to individual functions or to entire scripts. It doesn’t apply to block statements enclosed in {} braces; attempting to apply it to such contexts does nothing.
To invoke strict mode for an entire script, put statement “use strict” before any other statements.
To invoke strict mode for a function, put statement “use strict” in the function’s body before any other statements.

Q.48. What is function closure?

A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables.

Q.49. What is callback function?

A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of action is called as callback function.
function showName(name) {
alert(‘User name is:’ + name);
function displayName(callback) {
var name = prompt(‘Please enter name to be displayed’);


Q.50. What is setTimeout function?

The setTimeout() function executes function at specified interval=>
setTimeout(expression, timeout);
expression is the function/code that is called only once
timeout is number of milliseconds to wait before calling the function.
The clearTimeout() function is used to deactivate or cancel timer set by setTimeout() fuction.

Q.51. What is setInterval function?

The setInterval() function executes a function after a specified time interval=>
setInterval(expression, timeout);
expression specifies function/code to be called after particular time interval.
timeout specifies the time interval between function calls.
The clearInterval() function is used to cancel or deactivate the timer set by setInterval() function.

Q.52. What is difference between setInterval and setTimeout functions?

The setTimeout(expression, timeout) runs the function once after timeout whereas The setInterval(expression, timeout) runs the function in intervals repeatedly, with length of timeout between them.

Q.53. What is encodeURI() method?


The encodeURI() method encodes a Uniform Resource Identifier by replacing each instance of particular characters by one, two, three or four escape sequences representing UTF-8 encoding of character.

Q.54. What is decodeURI() method?

The decodeURI() method decodes a Uniform Resource Identifier previously created by encodeURI().

Q.55. What are Events?

Events are actions or occurrences that happen in the system you are programming to which you can respond in some way. Events are handled by function know as event handler.

Q.56. What are different events in Javascript?


Few of the important events are listed below:

Input Events

  • onsubmit – triggers on submitting a form.
  • onselect – triggers on selecting an element.
  • onchange – triggers when changes happen to an element.
  • onfocus – triggers when windows gets focus.
  • onreset – triggers when user clicks reset button.
  • onblur – triggers when window loses focus.
  • onkeyup – triggers on releasing a key.
  • onkeydown – triggers on pressing a key.

Click Events

  • onclick – trigger on clicking a mouse button.
  • ondblclick – triggers on double clicking mouse button.

Mouse Events

  • ondrag – triggers when element is dragged.
  • ondragend – triggers when drag ends.
  • ondragstart – triggers when drag starts.
  • ondragenter – triggers when dragged element is dropped.
  • ondragleave – triggers on leaving target while dragging element.
  • onmouseover – triggers when mouse pointer moves over element.
  • onmousedown – triggers on pressing mouse button.
  • onmouseup – triggers on releasing mouse button.
  • onscroll -​ triggers on scrolling a scroll bar of an element.

Load Events

  • onload- triggers when page has been loaded.
  • onerror- triggers when an error occurs when loading an image.
  • onunload- triggers when browser closes document.

Q.57. What are event handlers?

Event handler is a routine that is used to deal with event, allowing programmer to write code that will be executed when event

Q.58. What is addEventListener() method?

The addEventListener() method attaches an event handler to specified element.
You can add multiple event handlers to one element. It is possible to add event listener to any DOM object.
document.getElementById(“someUniqueDivId”).addEventListener(“click”, respondtoclick);
function respondtoclick() {
console.log(“Do some stuff!!!”);


Q.59. How to remove event listener from any element?

The removeEventListener() is an inbuilt function in JavaScript which removes an event handler from an element for attached event. Below example show how to remove event listener which was added in previous example.

e.g. document.getElementById(“someUniqueDivId”).removeEventListener(“click”, respondtoclick);

Leave a Comment

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

Scroll to Top