JavaScript Important Questions For Job Interview;

Lest Figure Out Some Interesting JavaScript Questions:

Shapan Miah
3 min readMay 8, 2021

How Javascript Code Execute:

Mainly has one engine for javascript run. Javascript firstly reads source code and next parser the code and then creates abstract syntax tree for interpreter ignition and compiles code next optimized. This is the javascript running process.

Truthy And Falsy Value:

If you compare number value then (0) is false value and other number is true value. when you string compare then (“”) empty string is false value and other string is true value. Some example of true and false value:

If we are run if- else condition then output is below;

const num= 10; // return true value.
const num = 0; // return false value.
const num = null || undefine; // return false value.
const num = NaN; // return false value.
const num = false // return false value.
const name = “jhon”// return true value.
const name = “”// return false value.
const name = null || undefine; // return false value.
const name = " " // return true value.
const name = false // return false value.

Explore Double (==) Equal:

Code example one:

const applePrice = 100;
const orangePrice = 120;
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is false.

Code example two:

const applePrice = 100;
const orangePrice = 100;
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is true.

Code example three:

const applePrice = 100;
const orangePrice = "100";
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is true.

Note: double equal (==) compare only value. So this condition is true.

Explore Triple (===) Equal:

Code example one:

const applePrice = 100;
const orangePrice = 100;
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is true.

Code example two:

const applePrice = 100;
const orangePrice = 120;
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is false.

Code example three:

const applePrice = 100;
const orangePrice = "100";
if(applePrice == orangePrice){
console.log(condition is true);
}else{
console.log("constion is false")
};
return condition is false.

Note: Triple equal (===) compare data type not only value. So this condition is false.

Difference Between bind, call and apply:

Let’s see an example:

Example of bind:

Bind means another object use bind to borrow method from another object. and this bind return output is according to won object.

const eidShoping{
product= "shirt";
price= 450;
payment: function(vat){
this.price = this.price + tax;
return price;
}
};
const wedingShoping {
product: "shirt";
price = 350;
};
const totalPayment = eidShoping.payment.bind(wedingShoping);
totalPayment(50);
// return price = 400

Example of call:

Call methods are different to bind methods, According to call methods is no need create another object, just call this object and return same output.

const eidShoping{
product= "shirt";
price= 450;
payment: function(vat){
this.price = this.price + tax + rent;
return price;
}
};
eidShoping.payment.call(wedingShoping, 50, 20);
// return price = 520

Example of apply:

Apply methods are different to call methods, According to Apply methods is no need create another object, just apply this object and return same output.

const eidShoping{
product= "shirt";
price= 450;
payment: function(vat){
this.price = this.price + tax + rent;
return price;
}
};
eidShoping.payment.apply(wedingShoping, [50, 20]);
// return price = 520

How To Remove Duplicate Item From Array:

We can remove duplicate item to implement with this methods;

const num = [10, 14, 30, 23, 34, 14, 89, 35, 23, 67, 45, 34]
const newNum = [];
for(let i = 0; i < num.length; i++){
const element = num[i];
const index = newNum.indexOf(element);
if(index== -1){
newNum.push(element);
}
}
console.log(newNum); // return [10, 30, 89, 35, 67, 45]

How To Find The Largest Element Of An Array:

We can find largest item to implement with this methods;

function bigName(names) {
let newBigName = [0];
for (let i = 0; i < names.length; i++) {
let element = names[i];
if (element.length > newBigName.length) {
newBigName = element;
}
}
return newBigName;
}
const friends = bigName([“shohag”, “kamal uddin”, “mahmudullah”]); console.log(friends);

How to Create a Fibonacci Sequence:

The Fibonacci sequence is one of the most famous formulas in mathematics. Each number in the sequence is the sum of the two numbers that previously it. So, the sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and more.

let fibo = [0, 1]for(let i = 2; i <= 10; i++){
fibo[i] = fibo[i-1] + fibo[i-2];
}
console.log(fibo);

--

--