A few tricky Concepts of JavaScript…

Shahin
4 min readNov 5, 2020

What the difference between null and undefined?

Commonly, we have got an error for undefined values. the value undefined means we declare a variable but never assigned a value to that variable. Because of that When we try to use that value it gives us undefined for that value. There is some more reason for getting undefined.

if we try to get a property from an object but there is no such property available then It gives us undefined for that property

suppose, we created an array with four elements. if we try to access an element which is not available in our array then it will throw undefined for that element

The programmers use a null value for the absence of an object. If you see null either it is assigned to a variable or returned from a function. “null” values are intentionally used for the absence of an object.

So, we can say that “undefined” is a primitive value which is set automatically with a declared variable (if we do not assign a value to that variable), and “null” is also a primitive value which is intentionally assigned to a variable for the absence for an object.

What is the difference between double equal(==) and triple equal(===) in JavaScript?

We always use conditional statements in our JavaScript code. there we need to compare the variables. we have used Comparison operators. there are two different types of comparison operators. when we compare variables data using the double equal(==) operator, it only compares the values of the variables. if we compare “5” and 5 its output will be true. if we see it carefully the values are equal but the types are different one of them is a string and another is a number.

console.log(“5” == 5); // the output will be true;

But if we compare those values with a triple equal(===) operator. it will show us false. Because it will compare the values and the types of values.

console.log(“5”===5); the output will be false;

What are the false values in JavaScript?

In a journey with JavaScript sometimes we need to check that the values which are taken from users are true or false. JavaScript has some false values and the values type also different by its nature. The false values are —

Empty string(“”), 0, false, undefined, null, NaN

All other values are true values except those above.

What the difference between Global scope and Block scope?

In JavaScript, Global Scope means the entire scope which is not bound with Brackets, and Block Scope is created with the brackets. If we declare a variable in Global Scope. We can access the variable from anywhere. But if we declare a variable in Block Scope. We can not access the variable from outside of the Block Scope. Suppose we declare a variable in a Function block. it will be only available in that function block. we can not access it from the outside of the function block

We can try this code in our Chrome console.

What is the “new” keyword in JavaScript?

We can create an object skeleton by class When we need to create some object in a specific structure. we can call the class by the “new” keyword. The “new” keyword creates objects by using the class. We need the “new” keyword when we want to create an instance of user-defined objects. besides, we can use it to call a built-in object which has a function constructor. such as

const data = new Date();

What is the “this” keyword in JavaScript?

Previously in JavaScript “this” is so confusing for developers especially for the new developers. But recently developers are not using “this” keyword so much. its used sometime with classes. when we use “this” keyword in object’s method it will represent the whole object. the value of “this” keyword always determined by how a method will called or which object is using the method or function.

If you look at the example above, you can see that “this” key word working like a object. something like we are adding a property with values in a object. when we use the class for creating person1 object. First of all “this” keyword holds an empty object then it takes the parameter and set it like a object. this.name is as person1.name.

--

--

Shahin
0 Followers

passionate web developer and I am enthusiast about learning new things for web development