8000 variable lookup · last-endcode/JavaScript-Basics@814fec6 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 814fec6

Browse files
committed
variable lookup
1 parent a951d06 commit 814fec6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

32_variable_lookup.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Lookup variable
2+
// js always lookup variable
3+
4+
const numGlobal = 100;
5+
6+
function total(num1, num2) {
7+
//120 cz use numGlobal 100, but if inside function
8+
//has nameGlobal with 50 result be 70
9+
const numGlobal = 50;
10+
const result = num1 + num2 + numGlobal;
11+
//inner function
12+
function multiply() {
13+
//if result * numGlobal use value in function total
14+
// sum be 3500, same with total function
15+
// if multiply has local nameGlobal 1000 sum be 70000
16+
const numGlobal = 1000;
17+
const sum = result * numGlobal;
18+
console.log(sum); //70000
19+
}
20+
multiply();
21+
return result;
22+
}
23+
24+
const result = total(10, 10);
25+
console.log(result);

0 commit comments

Comments
 (0)
0