The 10 Most Tricky JavaScript Interview Questions

Anup Paul
5 min readMay 8, 2021

What are the truthy and falsy values in Javascript?

In JavaScript, truthy and falsy values are evaluated as true and false. It’s called a boolean expression.

Without 0, all numeric values are truthy value.
Example:
const value = 10
if(value){
console.log(‘condition-true’);
}
else{
console.log(‘condition-false’);
}
output:condition-true

const value = 0
if(value){
console.log(‘condition-true’);
}
else{
console.log(‘condition-false’);
}
output:condition-false.

This is the same with string. If we assign an empty string, it will be false; however, if we assign anything in the curli braket, it will return true.
But this is different for arrays and objects. If our array and object is empty, it will be truthy value.
Example:
const country = “Bangladesh”
if(country){
console.log(‘condition-true’);
}
else{
console.log(‘condition-false’);
}
output:condition-true

const country = “”
if(country){
console.log(‘condition-true’);
}
else{
console.log(‘condition-false’);
}
output:condition-false.

And also if we not declear any value in the variable so this value will be undefiend.Undefiend value also is a falsy value. And if we declear a value by NaN and null this is also a falsy value.
So, in summary, all falsy values are false, 0, “”, undefiend, NaN, null
and truthy values are “0”, “ “, [], {} and all neumeric values are truthy value.

What is the difference between undefined and null?

Undefined means a variable has been decleared but not defined.
const x;
console.log(x); //output:Undefiend
Also, in object and array, if we try to read a value that is not defined in the object or array, it will return undefined.
const student:{name:’anup’}
console.log(student.id)//output:Undefiend.
const x=[1, 2, 3]
console.log(x[20])//output:Undefiend.
Null means an empty. This value is assigned but this value has nothing.
Null is a empty object.
const test = null;
console.log(test);//output: null

What is the difference between double equal and triple equal?

Double equal is used for assigning values to variables. When comparing two values, double equal is used. Double equal don’t check the values data type.
On the contrary, triple equal check the variable perfectly. Triple equal check the value and also check the type of these value. If we use triple equal we get the exact value what we want.
example:
const x = ‘10’;
if(x==10){
console.log(‘true’)
}
else{
console.log(‘false’)
}
output:true

const x = ‘10’;
if(x===10){
console.log(‘true’)
}
else{
console.log(‘false’)
}
output:false

Tell me something about scope

We can think that scope is an area. There are two types of scope. One is global scope and the other one is local scope.

The function is local scope. If in the function we declare any value by using let and const, this value can not be accessible outside the function. This is a local variable. In addition, if we declare a value using let and const in the for loop and if else condition, that value can not be accessible outside the scope.

example:
for (let i = 0; i < 3 ; i++) {
const element = i;
console.log(element);

}
output: 0 1 2

for (let i = 0; i ❤; i++) {
const element = i;

}
console.log(element);
output: error

On the contrary, if we declare a value outside the function by using let or const, it will be the global variable and this is called global scope. When we declare a value in global scope, it can be accessible from anywhere.
example:
let element;

for (let i = 0; i <10; i++) {
element = i;

}
console.log(element);
output: 9

Do you know about arrow function?

This arrow function is introduced in ES6. This is alternative version of a normal function. Arrow function can be complete in one line. If we are complete in one line nothing have tor return.
const double = x => x*2;
console.log(double(5));//output: 10
if we use more then one parameter in arrow function we have to use first bracket.
const sum = (x,y) => x+y;
console.log(sum(2,2));//output: 4
If we use multiple line in arrow function then we have to write the code in second braket and we have to use return.
const doMath = (x,y) =>{
const sum = x+y;
const mul = x*y;
return result = mul — sum;
}
const output = doMath(2,3)
console.log(output);//output: 1

What is JavaScript?

JavaScript is a lightweight, interpreted or just-in-time compiled, single-threaded, and dynamic programming language. Interpreted means read the code line by line and and give output immediately. For immediate out put this is call just in time compiled. And JavaScript is a dynamic language because we don’t have to assign the type of a numeric value when we declare it.

Do you know anything about v8?

There is an engine which helps to run JavaScript in the chrome browser. This engine’s name is v8Engine. This v8 engine code is written by C++ programing language. When we run JavaScript code, the v8 engine optimizes the code and compiles just in time.

What is DOM?

When a browser parse and read the HTML file at that time, this html file will be ready in JavaScript object model. Which is called DOM(Document Object Model) By using this object model, we can change or modify the html file in real time. Real time means when the user uses this web site.

What is call back function?

A call back function is a function that passed another function as a parameter.
function welcomeGust (name, greeting){
greeting(name)
}

function greetMorning(name){
console.log(‘hello’, name);
}
function greetEvening(name){
console.log(‘hello’, name);
}
welcomeGust(‘Dhiman’, greetMorning);//output:hello Dhiman
welcomeGust(‘Goutam’, greetEvening);//output:hello Goutam

Callback function make sure that a function is not going to run before a task is completed but this function will run right after the task has completed.

What is API?

Api(Application Programming Interface) is the way to load data from the server. By using api, we can load data from the server and show data in the browser.

As example we can imagine that the waiter is the api of the restaurant and imagine you are setting at the table with menu of restaurant which you order for and kitchen is the system to prepare your order. So the waiter is the man who serves the order from the kitchen which I ordered.

--

--

Anup Paul
0 Followers

Quick learner and a hard-working developer. Like to solve challenges and learn from them