-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoping-practice.js
More file actions
35 lines (25 loc) · 817 Bytes
/
scoping-practice.js
File metadata and controls
35 lines (25 loc) · 817 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
32
33
34
35
function calcAge(birthYear) {
const age = 2037 - birthYear;
function printAge() {
let output = `${firstName}, you are ${age}, born in ${birthYear}`;
console.log(output);
if (birthYear >= 1981 && birthYear <= 1996) {
var millenial = true;
// Create a new variable with same name as outer scopes variable
const firstName = 'Ram';
// Reassigning outer scope variable
output = 'NEW OUTPUT';
const str = `Oh, and you are a millenial, ${firstName}`;
console.log(str);
function add(a, b) {
return a + b;
}
}
console.log(millenial);
console.log(output);
}
printAge();
return age;
}
const firstName = 'Debu';
calcAge(1991);