Scope, Block Scope, Global Scope, Global Variable,Double equal (==) vs Triple equal (===)
Published: 2021-12-21 14:57:03

**Scope, Block Scope, Global Scope, Global Variable,Double equal (==) vs Triple equal (===)**

**Scope :** Scope is very important in programming. Scope refers to everything contained within "{}". Variable functions within a scope can only be accessed within that specific scope .

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkau76jbj3ldtk6cvmdu.PNG)
Everything contained in the picture in this image is bound within this particular scope. No access will be available to them outside the scope.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sirno0qlx8glulfz5m7q.PNG)
Whenever I try to log the console outside the scope of the "result" within the, the result is not defined as being outside the scope. So variables declared within a JavaScript function, become Local Scope to the function.

**Global Scope and Global Variable :** If a variable is declared inside a JavaScript file outside of a local scope, it may be accessible from all locations in that file, this is called global scope. In this picture, we can see the “first” variable is declared on top of the function and it is not bound by any "{}". So we can use the "first" variable anywhere in the file So. it is within the global scope and the variable is a global variable.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/228uwvigell8oq0ksiin.PNG)


**Block Scope:**  Let and const are the two keywords that provide block scope in JavaScript.The new JavaScript ES6 introduces these two important keywords. So the variables using let and const can only be accessed within their scope.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qf11c2tncbpri57fi3ts.PNG)

In this picture I am using the const keyword to declare a variable . So this keyword maintains block scope. Since I logged the 'blockVariable' console between {} for which the variable ran on the console.
But when I log the 'blockVariable' console outside of {}, the variable cannot find the console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1glzyh1z5tok7yq2295l.PNG)

**Double Equal(==) and Triple Equal(===) :** Double Equals ( == ) checks for value equality only.  And the other hand, Triple Equals ( === )  will verify whether the variables being compared have both the same value AND the same type .

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwl7slrvszpo1nbhskg8.PNG)
In this picture , I am declaring two variables, one is number and another is string. Than I am using double equal (==) for compare these two variables. Double equals can not compare them strictly. It just matches them and gives the answer.

On the other hand, when I can using triple equal(===), here the answer is “both numbers are not equal” ,because triple equal(===) can check them strictly.This means both the **type** and the **value **we are comparing have to be the same.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7s81irsct4h4nfohlq6.PNG)
If we have to compare an argument, we use triple equals, because it also compares type and value.So the result gives absolutely right. That's why programmers use Triple Equal.