#8 🛑 Scope and Scope Chain in JS | Reference Comparison | == vs == | - adarshtiwari1998/JavaScript-Crash-Course-Project-v1 GitHub Wiki

*****************************Tutorial Start đŸ”Ĩ ********************************

Important Question

Question 1: Difference between "==", "===" operators?

"==" operator values ko compare karta hai. <!--JAVASCRIPT EXAMPLE HERE, Please check repository code-->


Question 2: What is NaN property in javascript?

(NaN)Not a Number, it indicates a value which is not a legal number.

typeofNan(); will be return a number.


Question 3: Reference comparison

Array is reference data type we will discuss this in the previous lecture.

<!--JAVASCRIPT EXAMPLE HERE, Please check repository code-->


Question 4: Explain scope and scope chain in javascript

Scope determines the accessibility of the variables and function in various parts in single code base.

Scope determines where the function is can be used or not in the code.

Scope hame ye batata hai, suppose hamare paas code hai, too hum scope ki help se pata kar sakte hai ki kis jagah hum function use kar sakte hai aur kis jagah nhi.

In javascript there are 3 types of scope

  1. Global Scope
  2. local or function scope
  3. Block Scope

Global Scope jo variable or function hum global namespace me declare karege.

Global means Maximum accessibility (like public in java), it can be use from anywhere.

Aik baar global me variable defined kar do aur usko kahi pe bhi use kar lo.

<!--JAVASCRIPT EXAMPLE HERE, Please check repository code-->

Function Scope

Agar hum koi bhi variable banate hai function ke under too hum usko function ke andar hi use kar sakte hai. Not access outside of the function , only access inside of the function scope.

Function scope means(inside function)

agar koi variable declare karte hai function me too voo function ke andar hi use hoga.

<!--JAVASCRIPT EXAMPLE HERE, Please check repository code-->

** Block Scope**

Block scope related hai basically 2 variable se (let, const)

Agar hum variable declare kar dia let ki help se, if condition me, too hum isko kewal if condition ke andar hi isko use kar payege.

<!--JAVASCRIPT EXAMPLE HERE, Please check repository code-->

*****************************Tutorial End 🚀 ********************************