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.
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;
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?
We can try this code in our Chrome console.
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();
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.