Top 15 Javascript Interview Questions!

Nadim Mahmud
3 min readMay 8, 2021


1.What is JavaScript?

JavaScript is a client-side and server-side scripting language inserted into HTML pages and is understood by web browsers. JavaScript is also an Object-based Programming language

2.What are the key features of javascript?

JavaScript is a scripting language. JavaScript is an interpreter-based scripting language. JavaScript is case-sensitive. JavaScript is an object-based language as it provides predefined objects. Client-side JavaScript is very fast because it can be run immediately within the client-side browser.JavaScript is relatively simple to learn and implement.

3. What are JavaScript Data Types?

Following are the JavaScript Data types:

  • Number
  • String
  • Boolean
  • Object
  • Undefined

4.Check a number is a Prime Number or not?

function isPrime(num) {
for(var i = 2; i < num; i++)
if(num % i === 0) return false;
return num > 1;

5.Reverse a string in JavaScript

function reverseString(str) {

// empty string
let newString = "";
for (let i = str.length - 1; i >= 0; i--) {
newString += str[i];
return newString;

// take input from the user
const string = prompt('Enter a string: ');

const result = reverseString(string);

6.Find the largest element of an array in JavaScript

function mega Friend(arrayOfName)

{ var largestName = arrayOfName[0];

for (i = 1; i < arrayOfName.length; i++) { if (arrayOfName[i].length > largestName.length) { largestName = arrayOfName[i]; } }

if(largestName.length>0){ return largestName; }

else{ return “Please enter a valid name.” } }

var result = megaFriend([‘Nadim Mahmud’,’Nadim Mahmud Nil’,’Mahmud’,’Md Nadim Mahmud Nil’,’Md Nadim Mahmud’,’Md Mahmud’,’Nadim’,’Md Nadim Mahmud nel’]);


7.Remove duplicate item from an array in JavaScript

var names = ["Nadim","Mahmud","Nil","Md","Jalil","Khan","Ummay"];
var uniqueNames = [];
$.each(names, function(i, el){
if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);

8.Counting words in String in JavaScript.

var str = “JavaScript is a client-side and server-side scripting language.”;

var count = 0; for(var i = 0; i<str.length;i++){

var element = str[i];

if(element == “ “)

{ count++;


console.log(“number of words:”, count)

9. What is an undefined value in JavaScript?

Undefined value means the

  • Variable used in the code doesn’t exist
  • Variable is not assigned to any value
  • Property does not exist.

9. What is ‘this’ keyword in JavaScript?

‘This’ keyword refers to the object from where it was called.

10.Difference between “==” and “===”?

“==” checks only for equality in value, whereas “===” is a stricter equality test and returns false if either the value or the type of the two variables are different.

11. What is event bubbling?

JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of the parent will also work as if it were clicked too.

12 What are global variables? How are these variables declared?

Global variables are available throughout the length of the code so that it has no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.


// Declare a global: globalVariable = “Test”;

13.What are undeclared and undefined variables?

Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.

Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

14.How do closures work in JavaScript?

The closure is a locally declared variable related to a function that stays in memory when it has returned.

15.What is DOM in JavaScript?

JavaScript can access all the elements in a web page using the Document Object Model (DOM). The web browser creates a DOM of the webpage when the page is loaded.



Nadim Mahmud

My name is Nadim Mahmud. I am a software developer with extensive knowledge in programming, web development, mobile development, and database design.