Block Scope - Discussion

2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€87.69
List Price:  €122.77
You save:  €35.08
£75.17
List Price:  £105.24
You save:  £30.07
CA$138.15
List Price:  CA$193.41
You save:  CA$55.26
A$156.01
List Price:  A$218.42
You save:  A$62.41
S$131.13
List Price:  S$183.59
You save:  S$52.46
HK$775.83
List Price:  HK$1,086.19
You save:  HK$310.36
CHF 82.37
List Price:  CHF 115.32
You save:  CHF 32.95
NOK kr1,040.74
List Price:  NOK kr1,457.09
You save:  NOK kr416.34
DKK kr654.68
List Price:  DKK kr916.58
You save:  DKK kr261.90
NZ$167
List Price:  NZ$233.81
You save:  NZ$66.80
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,244.69
List Price:  ৳17,143.06
You save:  ৳4,898.36
₹8,541.58
List Price:  ₹11,958.56
You save:  ₹3,416.97
RM439.21
List Price:  RM614.91
You save:  RM175.70
₦161,317.86
List Price:  ₦225,851.46
You save:  ₦64,533.60
₨28,073.90
List Price:  ₨39,304.58
You save:  ₨11,230.68
฿3,339.06
List Price:  ฿4,674.82
You save:  ฿1,335.76
₺3,828.72
List Price:  ₺5,360.36
You save:  ₺1,531.64
B$572.08
List Price:  B$800.93
You save:  B$228.85
R1,857.55
List Price:  R2,600.64
You save:  R743.09
Лв171.49
List Price:  Лв240.10
You save:  Лв68.60
₩142,204.87
List Price:  ₩199,092.51
You save:  ₩56,887.63
₪366.59
List Price:  ₪513.24
You save:  ₪146.65
₱5,655.18
List Price:  ₱7,917.48
You save:  ₱2,262.29
¥14,198.32
List Price:  ¥19,878.22
You save:  ¥5,679.89
MX$1,953.70
List Price:  MX$2,735.25
You save:  MX$781.55
QR364.07
List Price:  QR509.71
You save:  QR145.64
P1,376.72
List Price:  P1,927.47
You save:  P550.74
KSh12,943.70
List Price:  KSh18,121.70
You save:  KSh5,178
E£5,094.13
List Price:  E£7,131.98
You save:  E£2,037.85
ብር13,446.70
List Price:  ብር18,825.91
You save:  ብር5,379.21
Kz91,690.83
List Price:  Kz128,370.83
You save:  Kz36,680
CLP$95,242.47
List Price:  CLP$133,343.27
You save:  CLP$38,100.80
CN¥731.15
List Price:  CN¥1,023.64
You save:  CN¥292.49
RD$6,020.55
List Price:  RD$8,429.01
You save:  RD$2,408.46
DA13,234.77
List Price:  DA18,529.21
You save:  DA5,294.44
FJ$225.30
List Price:  FJ$315.43
You save:  FJ$90.13
Q776.33
List Price:  Q1,086.89
You save:  Q310.56
GY$21,142.77
List Price:  GY$29,600.73
You save:  GY$8,457.95
ISK kr12,708.72
List Price:  ISK kr17,792.72
You save:  ISK kr5,084
DH928.92
List Price:  DH1,300.53
You save:  DH371.60
L1,718.78
List Price:  L2,406.37
You save:  L687.58
ден5,396.62
List Price:  ден7,555.49
You save:  ден2,158.86
MOP$805.16
List Price:  MOP$1,127.26
You save:  MOP$322.09
N$1,878.49
List Price:  N$2,629.97
You save:  N$751.47
C$3,709.18
List Price:  C$5,193
You save:  C$1,483.82
रु13,729.94
List Price:  रु19,222.47
You save:  रु5,492.52
S/373.49
List Price:  S/522.91
You save:  S/149.41
K416.97
List Price:  K583.78
You save:  K166.80
SAR375.05
List Price:  SAR525.09
You save:  SAR150.03
ZK2,869.58
List Price:  ZK4,017.53
You save:  ZK1,147.95
L436.50
List Price:  L611.12
You save:  L174.62
Kč2,193.75
List Price:  Kč3,071.34
You save:  Kč877.59
Ft35,836.25
List Price:  Ft50,172.18
You save:  Ft14,335.93
SEK kr958.55
List Price:  SEK kr1,342.01
You save:  SEK kr383.45
ARS$110,318.96
List Price:  ARS$154,450.96
You save:  ARS$44,132
Bs696.42
List Price:  Bs975.02
You save:  Bs278.59
COP$431,407.96
List Price:  COP$603,988.40
You save:  COP$172,580.44
₡50,669.87
List Price:  ₡70,939.85
You save:  ₡20,269.97
L2,580.74
List Price:  L3,613.14
You save:  L1,032.40
₲806,732.12
List Price:  ₲1,129,457.25
You save:  ₲322,725.12
$U4,215.14
List Price:  $U5,901.37
You save:  $U1,686.22
zł376.49
List Price:  zł527.11
You save:  zł150.61
Already have an account? Log In

Transcript

The final kind of scope in JavaScript is block scope. So block scope is achieved by using the let, or const keywords inside of a block. Now, it was introduced in the ECMO script 2015 version of JavaScript. So before ECMO script 2015, we had two kinds of scope, global and private. And then after echo script 2015 was rolled out. We have three kinds of scope, global, private, and block level scope.

So you may be asking yourself, what is a block? Well, this is a black block is opening and closing curly braces. And inside of those curly braces, you put your code any code you put inside of those curly braces is block level code. So for example, I have this variable I and I declared it by using the link keyword, bow. So by using the let keyword inside of a block, I becomes scoped to that Block. Now I could also have another IV variable that's defined in this case globally, because once again, if any code that's not defined in a function is defined globally, so here I've got this global variable called I, and then I've got this other variable called is equal to 50 inside of the block, and these two can coexist very happily because the first one is globally scoped.

And the second one is block scoped. So I could also use the const keyword to create that second I variable, the differences. If I use the let keyword, I could turn around overwrite that variable, the next line of code, I could say, let i equal 50. And then I could say, let i equal 5000. No problem. But when I use the const keyword, that's a constant.

So once I do that, I cannot try to change I i is i. So if I say const i equals 50, and then say const i equals 5000. I'll get an error because I can't overwrite it. So the difference between let const is they both create block level variables or block scope. But const when you use that keyword, you cannot override it. So once again, there's three different ways now to create a variable there is var which creates private scope.

There's let which creates a block level are a block scoped variable. And there's the const keyword which also creates a block scoped variable, but that value assignment cannot be changed.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.