DEV Community

Cover image for Interview questions for JS With Answer

Posted on

Interview questions for JS With Answer

JavaScript, commonly known as JS, is a server-side programming language with a high level. Because JavaScript is widely utilized to create diverse online apps around the world, there are several possibilities for JavaScript development.

Candidates must pass the interview in order to get a job in JavaScript programming. Various JavaScript interview questions and responses are posed to them.

The list of JavaScript interview questions and answers that are most likely to be asked during the interview follows. Depending on their experience and other circumstances, candidates may be asked anything from simple JavaScript interview questions to advanced JS interview questions.

Let's Begin 

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 JavaScript Data Types?

Following are the JavaScript Data types:

  • Number
  • String
  • Boolean
  • Object
  • Undefined

3. Difference between “ == “ and “ === “ operators.

Both are comparison operators. The difference between both the operators is that,“==” is used to compare values whereas, “ === “ is used to compare both value and types. 

4. Which is faster between JavaScript and an ASP script?

JavaScript is faster. JavaScript is a client-side language,, and thus it does not need the assistance of the webserver to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript. Javascript now is also a server-side language (nodejs).

5. What is NaN property in JavaScript?

NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.

typeof of a NaN will return a Number .

To check if a value is NaN, we use the isNaN() function,

**Note- isNaN() function converts the given value to a Number type, and then equates to NaN.

6. Is it possible to break JavaScript Code into several lines?

Breaking within a string statement can be done by using a backslash, ‘\,’ at the end of the first line.

7. Which company developed JavaScript?

Netscape is the software company that developed JavaScript.

8. 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.

9. What is === operator?

=== is called a strict equality operator, which returns true when the two operands have the same value without conversion. 

10. Can an anonymous function be assigned to a variable?

Yes, you can assign an anonymous function to a variable.

11. What do you mean by NULL in Javascript?

The NULL value is used to represent no value or no object. It implies no object or null string, no valid boolean value, no number, and no array object.

12. What is the function of the delete operator?

The delete keyword is used to delete the property as well as its value.

13. What are escape characters?

Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes, and ampersands. Place backslash before the characters to make it display.

14. What are JavaScript Cookies?

Cookies are the small test files stored in a computer, and they get created when the user visits the websites to store information that they need. Examples could be User Name details and shopping cart information from previous visits.

15. What is the ‘Strict Mode in JavaScript, and how can it be enabled?

Strict Mode adds certain compulsions to JavaScript. Under the strict Mode, JavaScript shows errors for a piece of code, which did not show an error before, but might be problematic and potentially unsafe. Strict Mode also solves some mistakes that hamper the JavaScript engines from working efficiently.

Strict mode can be enabled by adding the string literal “use strict” above the file. 

16. What is for-in loop in Javascript?

The for-in loop is used to loop through the properties of an object.

The syntax for the for-in loop is –

for (variable name in object){
    statement or block to execute

17. Is JavaScript case sensitive? Give its example.

Yes, JavaScript is case-sensitive. For example, a function parseInt is not the same as the function Parseint. 

18. What boolean operators can be used in JavaScript?

The ‘And’ Operator (&&), ‘Or’ Operator (||), and the ‘Not’ Operator (!) can be used in JavaScript.

*Operators are without the parenthesis.

Support my work

Discussion (6)

jonrandy profile image
Info Comment hidden by post author - thread only accessible via permalink
Jon Randy

If I was presented with a test like this when interviewing for a position, I would be very concerned about joining the company. This is no way to determine how good a developer is. Regurgitating facts is no indicator at all as to whether they can write code. The interview process should be geared towards seeing how they think, and how they write code - seeing if they can "walk the walk" and not just "talk the talk".

mtrantalainen profile image
Info Comment hidden by post author - thread only accessible via permalink
Mikko Rantalainen

I think the answer given for question 11 is incorrect. You cannot use null to represent "null string" or "null number". Type of null is object so it can be used to represent a null object only

If you have variable x with s numeric value and run "x = null;" the x is no longer a number but an object.

If you really want to check if somebody understands JavaScript you have to ask what do variable hoisting, function hoisting or prototype inheritance mean. How prototype inheritance is different from class inheritance and does JavaScript have either one or both? Also ask what is a closure and how it's different from object properties.

martinromario55 profile image
Martin Romario Ntuwa

These seem to be questions asked in a CS exam and not in an office. How would knowing the creators of JS make me a better programmer? How would I waste my time preparing for an interview and then be asked if JS is case sensitive or not?

Everything you listed is just the principles of JS. You can know all this without even writing a single JS code. But what about stuff like APIs or security approaches or Frameworks.
Don't make JS look pathetic when it's not.

lukeshiru profile image
Info Comment hidden by post author - thread only accessible via permalink
LUKESHIRU • Edited on

I recently discussed this in a similar post, so I'll keep it short:

If you see this or similar questions in an interview that you could just google, then that's a 🚩 red flag 🚩, run away. No matter your seniority, there are things that should be more valuable from a candidate that if they know "What is JavaScript", so if the company is asking that, I promise you, it will be a bad experience to work with them.


Edit: 🤣 the author ( @coderhax ) hid my comment and the comments of other users just because we pointed out that this aren't good interview questions. That's a really shady attitude...

zippcodder profile image
Deon Rich

These seem like basics that anyone should know rather than interview questions.

abeerbangladesh profile image

Its primary or beginner level question.

Some comments have been hidden by the post's author - find out more