forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththis.js
More file actions
31 lines (23 loc) · 889 Bytes
/
Copy paththis.js
File metadata and controls
31 lines (23 loc) · 889 Bytes
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
console.log(this); // This gives empty object
// Output {}
var aa = 1;
console.log(global.aa); // Global scope is accessible to every where
// Output undefined
// Nodejs has Global object which is accessible in all file it has some predefined functions
// Blocked Objects
{
var a = 1;
const b = 2;
console.log(b);
}
console.log(a);// Output 1 as variable a is declared using var
console.log(a);
// console.log(b) // Output ReferenceError: b is not defined as b is defined using let it is going to be declared only in that block
const help = () => {
var a = 4;
const b = 2; // variables defined by let and const are accessible to there scope only
console.log(a); // This will not get printed unless and until function is called
};
console.log(a);// Output 1
// console.log(b); // Output ReferenceError: b is not defined as b is in function scope only
help(); // Output 4