Get ready for job (JavaScript) Interview questions : Part 1

SAJID
3 min readMay 8, 2021

Difference between NULL and Undefined

In JavaScript, Null means, there is nothing exist. Like space. No data type of NULL exist also. But, for undefined, it is not completely nothing. That means, it is declared but yet it is not defined. So, an undefined variable has a data type like integer, float, string, function or object which is not defined yet. But after definition, it won’t show error.

Double Equal (==) vs Triple Equal

‘=’ is an assignment operator. It will assign the value of right side to the left side. But when it came to ‘==’, it means to compare value of both side.
But ‘===’ means it will compare both side of it not only values but also their data type.

//Example of =
const num= 5;
//Example of ==
const x = (4 == 3);
// here false will be assign in x
//Example of ===
const check = (2 === “2”);

What is Closure

In JavaScript, when a function declared inside another function, and the other function is being called, in that case the first function is also being called. This is called closure in JavaScript.

function firstFunction() {
const x = 8;
function secondFunction(){
console.log("From 2nd function");
}
secondFunction();
}
firstFunction();

Encapsulation

One of the main fundamental of object oriented programming is ‘encapsulation’. It used for hide values or states of a structured data object inside a class, preventing unauthorized parties direct access to them. Encapsulation describes the idea of bundling data and methods that work on that data within one unit. This concept is also often used to hide the internal representation or state, of an object from the outside.

private variable

A private variable in JavaScript is only visible to the current class. It is not accessible in the global scope or to any of its subclasses. For example, we can do this in Java (and most other programming languages) by using the private keyword when we declare a variable. The way to declare and access a private member should be simple, convenient, and intuitive. It should be clear from the code whether or not a member is private. Private members should only be accessible within the scope(s) you choose.

‘This’ keyword

‘This’ keyword in JavaScript refers to the object it belongs to. In a function, this refers to the global object. In strict mode, this is undefined. It refers to the current object in a method or constructor. The most common use of the ‘this’ keyword is to eliminate the confusion between class attributes and parameters with the same name.

Event bubble

Event bubbling is a type of event propagation where the events first triggers on the innermost target element, and then successively triggers on the ancestors of the target element till it reaches the outermost DOM element or document object.

Event loop

Event loop is the secret behind JavaScript asynchronous programming. The event queue is responsible for sending new functions to he track for processing. It follows the queue data structure to maintain the correct sequence in which all operations should be sent for execution. It runs the code line by line and adds functions to the call stack.

Recursion

Recursion is a process of calling itself. A function that calls itself is called a recursive function. It calls itself from inside of that function. In JavaScript, since functions are pass by reference, the function can be passed to itself as one of the arguments, and then called within the body of the function.

callback function

A callback is a function that is to be executed after another function has finished executing — hence the name ‘call back’. More complexly put: In JavaScript, functions are objects. Any function that is passed as an argument is called a callback function. Callbacks are generally used when the function needs to perform events before the callback is executed, or when the function does not (or cannot) have meaningful return values to act on, as is the case for Asynchronous JavaScript (based on timers) or XMLHttpRequest requests.

--

--