Important JavaScript interview questions you need to know
JavaScript is one of most popular programming language in the present world. This language has taken a big place in the tech world. Numbers of people are learning JavaScript. And also it has a high demand to the tech recruiters. There are some questions which are asked in most interview.

What is JavaScript?
JavaScript is single threaded, interpreted or just in time compiled, dynamic language. JavaScript is a client side language but it also can used in server side by a special way called node.
How JavaScript code executes?
When the browser receives the JavaScript code, it sends it to the browser engine. The engine converts the code into machine language by following ECMAScript. Then it sends the complete code back to the computer.
Write a function on how to calculate factorial of a number by recursive function?
function factorialRecursive(number) {if (number == 0)return 1;else {return (number * factorialRecursive(number - 1));}}console.log("Factorial of 11 is", + factorialRecursive(11));Output: Factorial of is 120
Write a function on how to create Fibonacci series by for loop ?
function fibonacci(n) {var n;var fibo = [0,1];for (var i=2; i<=n; i++){fibo[i] = fibo[i-1] + fibo[i-2];}return fibo;}console.log("fibonacci series till 5 ", fibonacci(5));
Output: fibonacci series till 5 [0, 1, 1, 2, 3, 5 ]
Write a function on how to create a Fibonacci series by recursive function?
function fibonacciRecursive(n) {if ( n == 0 ){return [0];}else if ( n == 1 ){return [0,1];} else {var fibo = fibonacciRecursive(n-1);var nextElement = fibo[fibo.length-1] + fibo[fibo.length-2];fibo.push(nextElement);return fibo;}}console.log("fibonacci series till 10 is ", fibonacciRecursive(10));Output: fibonacci series till 10 is [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
Write a function on how to check a number is a Prime Number or not?
function primeNumber(n) {for( i=2; i<n; i++){if( n%i==0 ){return n + " is not a prime number";}}return n + " is a prime number";}console.log(primeNumber(1));console.log(primeNumber(2));console.log(primeNumber(10));console.log(primeNumber(19));console.log(primeNumber(20));
Output :
1 is a prime number2 is a prime number10 is not a prime number19 is a prime number20 is not a prime number
What are falsy values in JavaScript?
A falsy value is a value that is considered false when encountered in a Boolean context, in JavaScript. The falsy values are:
the number 0
the BigInt 0n
the keyword null
the keyword undefined
the boolean false
the number NaN
the empty string "" (equivalent to '' or ``)
What are truthy values in JavaScript?
All values which are not falsy are considered as truthy value in JavaScript.
Null VS Undefined
Null is a value that can be assigned to a variable and represents ‘no value’.
And Undefined is a variable which has been declared, but no value has been given to it .
var nul = null;
var undefined; //defaults to undefined
Double equal (==) VS triple equal (===)
Double equal is used for comparing two variables, but it ignores the datatype of variables.
Triple equal is also used for comparing two variables, but this operator also checks datatype of variables.
const num = 0;
const str = '0';console.log(num == str); // true
console.log(num === str); // false
What is global variable in JavaScript?
Global variable is the variable which is called from outside of the function. Also variable who declared with window object are also global variable.
var globalVariable="I am a global as long as I'm outside a function";window.var = "I am totally a global Var"; //define a global variable
Write a function on how to remove a duplicate item from an array?
var numbers = [ 1,0,7,4,1,7,9,4,8,2,7,6,4,0,8,4,3,5,8,2,8,6,5,7 ];var unique = [];for ( i=0; i<numbers.length; i++ ){var element = numbers[i];var index = unique.indexOf(element);if ( index == -1 ){unique.push(element);} }console.log(unique);Output: [ 1, 0, 7, 4, 9, 8, 2, 6, 3, 5 ]
Write a function on how to reverse a string?
function reversing(str) {var reverse = "";for( var i=0; i<str.length; i++ ){var char = str[i];reverse = char + reverse;} return reverse;}console.log(reversing("REVERSE"));Output: ESREVER