Skip to content

Commit 41b90e5

Browse files
committed
Scope in javascript
1 parent 5cff306 commit 41b90e5

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

03_basics/02_scope.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
var c = 300
22
let a =400
3-
if(true){
3+
if(true){ // {}are scope
44
let a= 10
55
const b =20
66
var c =30
77
console.log("Inner: ",a);//10
88
}
99
console.log(a)//400
1010
console.log(c)//30
11-
console.log(b)//error
11+
//console.log(b)//error
12+
13+
function one(){
14+
const username = "kalpjeet"
15+
16+
function two(){
17+
const website = "youtube"
18+
console.log(username);
19+
}
20+
//console.log(website);// Error
21+
two()
22+
}
23+
if(true){
24+
const username = "hitesh"
25+
if(username == "hitesh"){
26+
const website = " youtube"
27+
console.log(username + website); //hitesh youtube
28+
}
29+
// console.log(website); error
30+
}
31+
//console.log(username); error
32+
33+
34+
//++++++++++++++++++++++++++++++++++++++++++++++++++++
35+
36+
function addone(num){
37+
return num+1
38+
}
39+
console.log(addone(5))//6
40+
41+
const addTwo = function(num){
42+
return num+2
43+
}
44+
console.log(addTwo(5)) //7

0 commit comments

Comments
 (0)