-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile50.js
50 lines (39 loc) · 1.13 KB
/
file50.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
// block scope vs function scope
// let and const are block scope means we can't access these outside the function
// var is the function scope means we can use it everywhere onece declare
// small example
{ // these are block
// const myName = "jitendra";
// let myName = "jitendra";
// console.log(myName);s
}
// we can't use it because it's outside the function
// console.log(myName);
{
// var myName = "khadoliya";
// console.log(myName);
}
// console.log(myName);
// so we saw here we can use access var outside the block scope
// real time example
// if always true in empety
// checking const outside the funtion
const myFanc = function() {
if(true){
const myName = "ankit";
console.log(myName);
}
// console.log(myName);
// cheking var outside of the function
const myFanc2 =()=>{
if (true) {
var lastName = "khadoliya";
console.log(lastName);
}
console.log(lastName);
}
myFanc2();
}
myFanc();
// there is little catch laxical approch is outside(upside) that's why const and let varibale returens value