JavaScript Interview Questions.

Apel Mahmud
6 min readDec 13, 2020

--

  1. What is JavaScript?

Answer: JavaScript is both server-side and client-side scripting language. It also now an object-based programming language. JavaScript inserted into HTML pages that can be understood and executed by the browser.

2. What are the data types in JavaScript?

Answer: Following are javaScript data types

  • number
  • string
  • boolean
  • null
  • undefined
  • symbol

3. What are the differences between Java and JavaScript?

Answer: JavaScript is a client-side and server-side scripting language. On the other hand, Java is an OOP (Object Oriented Programming Language) like C++. So, Java and JavaScript are totally different languages. JavaScript is now an Object-based programming language with Node.js.

4. Which company developed JavaScript?

Answer: Netscape is a software company that developed JavaScript.

5. Which symbol is used for comments in JavaScript?

Answer: Following are symbols used for comments in JavaScript-

// Used to create single-line comment and

/*..*/ Used to create multi-line comments.

6. Within JavaScript and an ASP script, which faster?

Answer: JavaScript faster than ASP script. ASP(Active Server Page) is slower.

7. Is it possible to break the JS code into several lines?

Answer: Yes, it is possible to break the javascript into several lines.

8. What are the differences between “==” and “===”?

Answer: “==” checks just value but “===” check two things such as data type and value.

9. How can the style or class of an element be changed?

Answer: document.getElementById(“Text”).style.width = “33px”

10. what are the looping structures in JavaScript?

Answer: Following are looping structures-

  • For loop
  • while loop
  • do-while loop

11. 1+2+3+"5" What would be the resulting output?

Answer: 1, 2, and 3 are added numerically and 5 is concate with string. So the result would be 65.

12. How many types of popup boxes available in JavaScript?

Answer: There are 3 types of popup boxes available in JavaScript as

  • alert() = alert popup box comes with only one button which is the ok button.
  • confirm() = confirmation box comes with two-button one is ok button and other is cancel button
  • prompt() = prompt popup box comes with input and two-button namely ok and cancel button.

13. Explain JavaScript cookies?

Answer: JavaScript cookies let you stored your information on a web page. Generally, I can say that-

  • When a user visits a web page, the cookies stored his information;
  • Next Time when a user visits the web page, the cookie remembers his information;
  • It also maintains a state of a user and stored data name-value pairs.

14. Please, Explain undefined value in JavaScript?

Answer: At first I say, It is not defined so we call is undefined. It also means, The variable has been declared but currently not assigned value under the variable. Like as (var a), It displays the undefined message.

15. What is negative infinity in JavaScript?

Answer: NEGATIVE_INFINITY property represents the negative infinity value. For example —

1.console.log(10/0)
2.//Infinity
3.console.log(-10/0)
4. -Infinity

another example-

var x = 10;
x.NEGATIVE_INFINITY // result undifined

16. Explain the JavaScript global variable?

Answer: A global variable declares outside a function. It has a scope namely global scope. We can access it from anywhere.

17. What is the isNaN function in JavaScript? Give example.

Answer: JavaScript isNaN function return false if the argument is number otherwise it returns false. Following are an example-

18. Please explain “this” keyword.

Answer: JavaScript “this” keyword refers to the object.

19. How to read and write a file using JavaScript?

Answer: There are two ways to read and write a file using JavaScript. One is “using javascript extension” and two is “Using web page and Active X object”.

20. What do you mean by null?

Answer: null is used to represent no value or no object. It is a primitive data type in javaScript.

21. Explain the delete operator in JavaScript?

Answer: JavaScript delete operator delete the property from an object. for example —

22. What is the difference between the “confirm ”and “alert ”popup box in JavaScript?

Answer:

i. confirm() = confirmation box comes with two-button one is ok button and other is cancel button.

ii. alert() = alert popup box comes with only one button which is the ok button.

23. What is the javascript escape characters?

Answer: Escape (\) characters used when working with special characters like double quotes, single quotes, apostrophes, etc. It set before the character to make it displays.

  • \n — for a new line
  • \t — for Horizontal tabular
  • \b — for Backspace
  • \” — for double quotes
  • \” — for single quotes

24. What is .pop() method in JavaScript?

Answer: .pop() method is like to shift() method. the pop() method takes the element from the end of the array. On the other hand, the shift() method takes elements from the beginning of the array.

25. Explain the break and continue statement?

Answer:

  • break statement = break statement stop his current loop and .
  • continue statement= The continue statement continue one iteration in the loop.

26. what are the two basic groups of data types in javascript?

Answer: There are two groups of data types in JavaScript —

  • Primitive types
  • Reference types

27. Give an example of generic objects?

Answer: Generic object can be created like -

const person = new Object()

28. What is the use of typeof operator? Give an example.

Answer: typeof operator used to check the variable and give and description of the variable.

const num = 4;
console.log(typeof(num)) //result = number;

29. How to handle exceptions in JavaScript?

Answer: try, catch, finally used to handle exceptions in JavaScript.

try{
//.......
}
catch(exp){
//....
}
finally{
//....
}

30. Which keyword used to print text on the screen in JavaScript?

Answer:

document.write(‘Hello world’)

31. What are the different types of JavaScript errors?

Answer: Following are 3 types of errors in JavaScript -

  • Load time errors
  • Run time errors
  • Logical errors

32. Explain the use of the push() method?

Answer: .push() method is like to unshift() method. push() method used to append or add one more element at end of the array. On other hand, the unshift() method used to add elements at the beginning of the array.

33. What is the difference between Jscript and JavaScript?

Answer: Jscript developed by Microsoft and JavaScript developed by Netscape.

34. Give an example JavaScript is case sensitive?

Answer: JavaScript is a case sensitive language.

const NAME = 'Mahmud'
const name = 'Ekramul' // Both are different

35. What are the boolean operators in JavaScript?

Answer: and (&&), or (||) , not (!).

36. What is the difference between let and var?

Answer: let is blog scope and var is function scope.

37. Please explain the ‘use strict’ mode.

Answer: JavaScript ‘use strict’ mode used to eliminates some silent errors by changing them to throw errors. It also makes secure javascript. Without declaring a variable we can not access it.

  • without “use strict”
  • With “use Strict”

38. What is an anonymous function in javaScript?

Answer: Anonymous function doesn’t have a name. for example —

function(){
//code here...
}

39. Draw a simple JavaScript DOM?

Answer: DOM stands for “Document Object Model”. Following is a simple javascript DOM.

JavaScript Document Object Model

If the article is helpful for you please touch the clap icon. It inspires me to write more articles. Thank you 🧑

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Apel Mahmud
Apel Mahmud

Written by Apel Mahmud

Jr. Software Engineer (React | React Native | Next | JS ) at Techvillage, Bangladesh | https://apelmahmud.vercel.app/

No responses yet

Write a response