10 Important JavaScript Interview Question
Question-1: How many types of JavaScript Falsy and Truthy Values and what are they?
Ans: In JavaScript, there were 5 types of Falsy Values, 0, “”, NaN, null, undefined. these are by default give a false and All of the components are JavaScript truthy values example: “high”, ‘0’, (empty function),{empty object},[empty array]
Question-2: What are the different Null and undefined.
Ans: In short Null means an empty or nonexistent value. Null is assigned and explicitly means nothing. while undefined typically means a variable has been declared but not defined yet.
Question-3: What is the difference between double equal or triple equal?
Ans: Double equal means it just checks the value not only that it can change one of values types for comparison and triple equal means it checks value and types.
Question-4: What is the difference between bind call and apply?
Ans: Call() The Call Method controls a function provides one by one with given ‘this’ value and arguments. Apply( ): The whole functionality works and allows to pass arguments as an array. Bind(): function returns a new function that allows passing in an array and any number of arguments.
Question-5: What is the Global Variable in javaScript?
Ans: In JavaScript, there was Global Scope and local scope but a declaration of variables and initialized the function at the outside becomes global variables. when a variable declared without a var keyword then it becomes a global variable automatically and the Global variable are can be accessed and modified anywhere in the program
Question-6: Say something about javaScript This keyword?
Ans: The Function this keyword behaves differently in javaScript compared to another programming language it has 2 different modes Strict mode and non-strict mode. the value of this is determined by how a function is called it means function execution time or its called run time of a function.
Example:
const test = {
prop: 50,
func: function() {
return this.prop;
},
};
console.log(test.func()); // output: 50
Question-7: How to remove a duplicate item from an array?
Ans: For first we have to convert an array of duplicates to a set. The new set will implicitly remove duplicate elements. then convert the set bake o an array. Example:
let chars = [‘A’, ‘B’, ‘A’, ‘C’, ‘B’]
let uniqueChars = […new Set(chars)];
console.log(uniqueChars); // output: [ ‘A’ , ‘B’ , ‘C’ ]
Question-8: Describe the Fibonacci series in a recursive way?
Ans: A fibonacci sequence is written as:
0, 1, 1, 2, 3, 5, 8, 13, 21 …
The Fibonacci sequence is the integer sequence where the first two terms are 0 and 1. After that, the next term is defined as the sum of the previous two terms. Hence, the nth term is the sum of (n-1)th term and (n-2)th term.
Question-9: How javascript code executes?
Ans: When the above code loads in the browser, the Javascript engine creates a global execution context and pushes it to the current execution stack. When a call to first() is encountered, the Javascript engines create a new execution context for that function and push it to the top of the current execution stack.
Question-10: What is DOM?
Ans: The Document Object Model is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document with a logical tree.