JavaScript interview question for internship

Truthy and Falsy values

Javascript truthy and falsy values are quite confusing for the newbie or beginner. When you want to see any value or data in boolean, as a result, you will get true or false. If you get true then the value will be truthy else falsy. There are a few falsy values in javascript and the rest of the values are truthy. Here are some examples of falsy value —

“” // (empty string) falsy valuenull, undefined \\ falsy valuefalse // falsy value

Null vs Undefined

The difference between null and undefined is really confusing. I am going to clear this confusion in a single sentence. If we don’t define a variable intentionally then it will be null. On the other hand, If we define a variable unintentionally then it will be undefined. As simple as that.

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

There is a little confusion with double equal and triple equal. Well, the concept is very simple. Duble equal only check the value and compare. On the other hand, triple equal checks both value and data type. So, if you do this (2==”2”), the output will be true. But if you do this (2===”2”), here the output will be false. Because 2 is a number data type and “2” is a string data type. So, they are not the same.

Block scope vs global scope

Well, the scope is all about variables. If we declare a variable inside a function, we can only use that variable inside that function. If we try to get the value of that variable we will get an error. Instead of declaring a variable in a function, if we declare a variable outside of a function we can get access of this variable in our entire javascript file. We can also get access of this variable inside a function.

Slice vs Splice

Slice and splice are quite confusing array methods. But both are used to take apart from an array. If we use slice we need to define from which index to which index we want. As a result, we will get an array from the defining starting index to before the defining ending index. And our main array will remain the same. In the splice method, we need to define the starting index and the number of values we want from the starting index. We will get an array as a result just like slice but our main array will be modified.

JavaScript Bind

The bind method is used to borrow a method or function from one object to another object. There are other ways to borrow a method or function from one object to another object. Suppose, we have two objects. The first object has a method called the salary which generates a net salary of that object. What if we want to use that method on the other object, We can do 2 things here. We can rewrite the same method again for the 2nd object or we can use the bind method to borrow the method or function from the 1st object to the 2nd object.

Asynchronous vs Synchronous

Synchronous transmission is fast. Asynchronous transmission is slow. Synchronous transmission is costly. Asynchronous transmission is economical. In Synchronous transmission, time interval of transmission is constant. In asynchronous transmission, time interval of transmission is not constant, it is random.

Arrow Function

Arrow is a new way to define a function. Arrow functions were introduced in the ES6 version of javascript. Arrow function is a shorter way to define a function. Here is an example of a normal function and arrow function -

normal function

arrow function

DOM

The full form of DOM is Document Object model. DOM is a programming interface for HTML and XML documents. When the browser tries to render a HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.

Recursion

Recursion is an alternative way to do the conditional rendering. Recursion is also faster than any other conditional statement. But it is little bit confusing and harder for the begainer. Recursion is all about function.

Hi there, I am a Junior Web Developer. I love to build interactive websites and travel around the world.