Skip to content

Commit f2be653

Browse files
JavaScript: Loops, Scopes, var/let/const
1 parent ee93c96 commit f2be653

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎JavaScript/Loops.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ <h1>Loops</h1>
148148
// break
149149
// }
150150
// }
151+
152+
// Example 4: Find the factorial of the given number
153+
// let num1 = Number(prompt('Enter number to find factorial'))
154+
// let factorial = 1
155+
156+
// for(let i = num1; i > 1; i--) {
157+
// factorial = factorial * i
158+
// }
159+
160+
// console.log(factorial)
151161
</script>
152162
</body>
153163
</html>

‎JavaScript/Scopes.html‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Scopes</title>
7+
</head>
8+
<body>
9+
<h1>Scopes</h1>
10+
<script>
11+
/*
12+
# Scope: Space where a variable can be accessed
13+
- Global scope: Variable can be accessed anywhere in the file
14+
- Function scope
15+
- Block scope ({}): Variable can be accessed within the block
16+
17+
# Declare variables
18+
- var, let, const
19+
- ES6: ECMAScript 6 (2015)
20+
- let, const (Block scope)
21+
22+
- var: Variables
23+
- Can be re-declared
24+
- Can be re-assigned
25+
- Function scope
26+
- let: Variables
27+
- Cannot be re-declared
28+
- Can be re-assigned
29+
- Block scope
30+
- const: Constants
31+
- Cannot be re-declared
32+
- Cannot be re-assigned
33+
- Block scope
34+
*/
35+
36+
// var x = 10 // Global scope
37+
38+
// if(10 > 5) {
39+
// console.log(x)
40+
// }
41+
42+
// console.log(x)
43+
44+
// var age = 35
45+
46+
// if(10 > 5) {
47+
// var age = 50
48+
// console.log(age)
49+
// }
50+
51+
// console.log(age)
52+
53+
/* ----------------------*/
54+
// let student = 'Mark'
55+
56+
// if(100 > 50) {
57+
// let student = 'Ananya'
58+
// console.log(student)
59+
// }
60+
61+
// console.log(student)
62+
63+
// var x = 10
64+
// x = 100
65+
// console.log(x)
66+
67+
// let x = 10
68+
// x = 100
69+
// console.log(x)
70+
71+
// const x = 10
72+
// x = 20
73+
74+
/* ----------------------*/
75+
// var name = 'Mark'
76+
// if(true) {
77+
// var name = 'Sonal'
78+
// }
79+
// console.log(name + name)
80+
81+
// let name = 'Mark'
82+
// if(true) {
83+
// let name = 'Sonal'
84+
// console.log(name + name)
85+
// }
86+
// console.log(name + name)
87+
</script>
88+
</body>
89+
</html>
90+
91+
<!--
92+
# Future:
93+
- Function scope
94+
-->

0 commit comments

Comments
 (0)