Some Interview Question

Tanvir Hossain Robin
3 min readMay 8, 2021

Truthy and Falsy values:

truthy and falsy values mean true and false. if any condition value is more than 0 then it will be true and if any condition value is 0 or less than 0 it will be false. if we write a string and the string length is more than 0 then it will be true. if we write an empty (“”) string then it will be false. if we write “ “ (white space) then it will be false because there is a space. if anything is undefined/null/NaN in js then it will be false. if there is an array/object then it will be true. if we set a value false then it will be false.

Null Vs Undefined:

when we forgot to define that will be undefined .when declare a variable but we forgot to define value it will be undefined. a function if we are not returning then it will be undefined. if we write return but not defined what will return, then it will be undefined. When we don't pass a parameter in a function, it will be undefined. when we want to access a property in an object but there is no property in an object then it will be undefined. when we set a value undefined then it will be undefined (don't do this).

The value null represents the intentional absence of any object value. we have to set null.

Double equal (==) vs Triple equal (===):

== in JavaScript is used for comparing two variables, but it ignores the datatype of a variable.=== is used for comparing two variables, but this operator also checks datatype and compares two values.

Scope, block scope, access outer scope:

Scope in JavaScript refers to the current context of code, which determines the accessibility of variables to JavaScript. and there are two types of Scope.

Global variables: are those declared outside of a block. we can access it anywhere.

Local variables: are that declared inside of a block. and we can only access in the function. if we declared with var then we can access it anywhere and we can call it hoisting.

Closure:

A closure is a combination of a function bundled together with references to its surrounding state. In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.

Difference between bind, call, and apply:

Call: The call() method invokes a function with a given ‘this’ value and arguments provided one by one. This means that we can call any function, and explicitly specify what ‘this’ should reference within the calling function.

Apply: Invokes the function and allows you to pass in arguments as an array.

Bind: returns a new function, allowing you to pass in an array and any number of arguments.

window:

The window represents a window in the browser. An object of the window is created automatically by the browser. Window is the object of the browser, it is not the object of javascript. The javascript objects are string, array, date, etc.

What is “this ”keyword:

if we use “this” inside of a method, inside of an object, or inside of class then “this ” represents those methods, objects, or class. This keyword’s value has nothing to do with the function itself, how the function is called determines this value it can be dynamic, based on how the function is called. You can change this context through call, apply and bind.

Javascript setTimeout:

The setTimeout method calls a function or evaluates an expression after a specified number of milliseconds. 1000 ms = 1 second.A function to be executed after the timer expires.

setInterval:

The setInterval method calls a function or evaluates an expression at specified intervals. It returns an interval ID that uniquely identifies the interval, so you can remove it later by calling clearInterval.

--

--