JavaScript Interview Questions

Q1. What is the output of

					
						console.log(typeof typeof 1);
					
				

A. string

Q2. What is the output of

					
						console.log(0.1 + 0.2 == 0.3);
					
				

A. false

Q3. What is the output of

					
						console.log(0.1 + 0.2 == 0.3);
					
				

A. false

Q4. How do you check if a number is an Integer?

					
						let n = 1;
						console.log(Number.isInteger(n));
					
				

A. true

Q5. What will be the result of the following?

					
						let n = 1.0;
						console.log(Number.isInteger(n));
					
				

A. true

Q6. A function is defined as

function f() {}

What will be its Boolean output? What is typeof f?

					
						function f() {};
						console.log(f? 1:2); // 1
						console.log(typeof f); // function
					
				

A. true

Q7. What will be the result of the program?

					
						var y = 1;

						if(function f() {}) {
						    y += typeof f;
						}

						console.log(y); // 1undefined
					
				

A. 1undefined

Q8. What will be the output of the following?

					
					if(false) {
					    var a = 1;
					    let b = 2;
					}

					console.log(a); // undefined
					console.log(b); // Reference Error
					
				

A. undefined and Reference Error

Q9. What will be the output of the following?

					
						let id = Symbol("id'");
						console.log(typeof id);
					
				

A. symbol

Q10. What will be the output of the following?

					
					(function() {
					    var a = b = 1;
					})();

					console.log(a); // Reference Error
					console.log(b); // 1
					
				

A. Reference Error and 1

Q11. What will be the output of the following?

					
						this.n = 2;    // 'this' refers to global window object
						var number = {
						  n: 3,
						  getN: function() { return this.n; }
						};

						console.log(number.getN()); // 3
					
				
					
						this.n = 2;    // 'this' refers to global window object
						var number = {
						  n: 3,
						  getN: () => { return this.n; }
						};

						console.log(number.getN()); // 2
					
				

A. 3 and 2

Q12. What is the difference between Object.freeze() and Object.seal()?

					
						this.n = 2;    // 'this' refers to global window object
						var number = {
						  n: 3,
						  getN: function() { return this.n; }
						};

						console.log(number.getN()); // 3
					
				
					
						this.n = 2;    // 'this' refers to global window object
						var number = {
						  n: 3,
						  getN: () => { return this.n; }
						};

						console.log(number.getN()); // 2
					
				

A. 3 and 2

Q13. What is the difference between .match() and .matchAll() in Regular Expressions?

A. .match() returns the occurence as strings, and .matchAll() returns as an array.