Some JavaScript topics to help you in the interview

Double equal (==) vs triple equal (===)

Triple equal is called strict equality. Triple equal always checks for the same type and same value. If the values have the same type and same value it returns true otherwise false.

Double equal, on the other hand, first try to convert both values to the same type then do check for equality.

Truthy value vs falsy value

In JavaScript, truthy value means it represents true value. Some truthy values are:

[], {}, true, ‘false’, -5, 5, 7.5

Falsy value means exactly what its name implies. 0, null, undefined, NaN is some falsy values.

Note that for number both negative and positive values are truthy except 0.

Null and Undefined

Null represents intentionally no value of an object. Null express no identity of a variable.

A variable that has no value yet, is undefined. A function is also undefined if that returns nothing.

Variable Scope

Variable scope means in which context it is accessible or can be used. The scope can be of two types. Local scope or block-level scope and global scope.

function myFunc() {
myFunc(); // Tomas
console.log(name); // Tomas

But if we do this

console.log(name);     // error

We can't access the name variable outside myFunc. This is a block-level variable or local variable.

Difference between bind, call, and apply

Sometimes we need to use a method of an object from another object. For this reason, bind or call or apply can be used

If we want to use reduce method of mainObject from another object we can bind this method

We can also call this reduce method, 250, 50);   // 5700

Or, using apply

mainObject.reduce.apply(anotherObjectApply, [250, 50]);   // 7700

The main difference between call and apply is that all arguments are passed using comma in call and in apply arguments are passed as an array.

Here are some basic but important problem solving using JavaScript.

Reverse a string

  for(let i = 0; i < str.length; i++) {
reverseStr = str[i] + reverseStr;
return reverseStr;

If we pass a string to the reverse function this will look like this:

console.log(reverse(myString));    // !dlroW olleH

Remove duplicate item from an array

  for(let i = 0; i < arr.length; i++) {    if(uniqueArray.indexOf(arr[i]) == -1) {
return uniqueArray;

This removeDuplicate will return an array of unique elements.

console.log(removeDuplicate(id));    // [4, 1, 7, 6]

Finding factorial using the recursive way

The factorial of a non-negative integer n is the product of all positive numbers less than or equal to n.

  if(n == 0) {
return 1;
return n * factorial(n - 1);
console.log(factorial(5)); // 120

Fibonacci number in a recursive way

Fibonacci series is a sequence of numbers, such that each number is the sum of the two preceding ones, starting from 0 and 1.

  if(n <= 1) {
return n;

return fibonacci(n - 1) + fibonacci(n - 2);
console.log(fibonacci(10)); // 55

Finding GCD of two numbers using euclidean algorithm

The greatest common divisor of two or more integers is the largest possible integer that devices each of the integers.

  if(b == 0) {
return a;
return gcd(b, a % b);
console.log(gcd(44, 5)) // 1
console.log(gcd(55, 11)) // 11

That’s all for today. Thank you for your time.