Site icon NgDeveloper

[2021] Top 10 Javascript beginners interview questions and Answers

1. What are JavaScript Data Types?

JavaScript has 5 Data types and these are,

2. What is the difference between == and === in Javascript ?

== [ comparison operator ]

=== [ strict comparison operator ]

3. What is the difference between let, var and const

let:

var:

const:

4. What are the different loops available in Javascript ?

5. What is the difference between null and undefined ?

null:

undefined:

6. What is dynamically typed language or Is javascript dynamically typed language ?

When you are creating the variable, you don’t want to worry about the value type you are going to assign in javascript as this is the dynamically typed language, which means value types can be changed during run time.

Example:

var pincode;
pincode = '600000'  // here 600000 is the string value
// again to the same variable pincode you can assign the number value as well
pincode = 600000 // here 600000 is the number value. // works without any issues

7. What is isNan in Javascript ?

Nan (Not-A-Number) to check the provided value is the number or not.

isNan() -> returns true if the provided value is not a number and returns false if the provided value is number.

console.log(isNaN("ngdeveloper.com")); // Returns true as "ngdeveloper.com" is not a number
console.log(isNaN(111)); // Returns false as 111 is the number
console.log(isNaN('111')); // Returns false, as '111' from string can be converted to Number type
console.log(isNaN(true)); // Returns false, since true converted to Number type (1)
console.log(isNaN(false)); // Returns false, since false converted to Number type (0)
console.log(isNaN(undefined)); // Returns true, as undefined is not a number

8. What is the difference between break and continue statement?

break:

continue:

9. Write the sample snippet to write the array & object in javascript ?

Creating an object in javascript:

var company = {
name: "Ngdeveloper",
domain: "ngdeveloper.com"
};

Creating an array in javascript:

var inputArray = [1, 2, 3, 4, 5];

10. What is typeof in javascript ?

typeof is a javascript keyword that returns the value of the variable.

Few examples:

console.log(typeof(1) == "number");  // Returns true, as 1 is of type "number"
console.log(typeof("ngdeveloper.com") == "string"); // Returns true as "ngdeveloper.com" is of type "string"
console.log(typeof(null) == "object"); // Returns true as "null" is of type "object"
console.log(typeof(undefined) == "undefined"); // Returns true as undefined is of type "undefined"
console.log(typeof(true) == "boolean"); // Returns true as "true" is of type "boolean"
console.log(typeof([]) == "object"); // Returns true as "[]" is of type "object" not "array"
Exit mobile version