-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_1.js
82 lines (49 loc) · 1.73 KB
/
Day_1.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Day 1: Variables and Data Types
// Activity 1: Variable Declaration
// Task 1: Declare a variable using var, assign it a number, log the value to the console
var num = 10;
console.log(num)
// Task 2: Declare a variable using let, assign it a string, and log the value to the console
let myName = "Farooq";
console.log(myName)
// Activity 2: Constant Declaration
// Task 3: Declare a variable using const, assign it a boolean value, and log the value to the console.
const language = "JavaScript";
console.log(language)
// Activity 3: Data Types
// Task 4: Create variables of different data types(number, string, boolean, object, array) and log each variable's type using the typeof operator
const numVal = 12;
const stringVal = "string";
const boolVal = true;
const objVal = {
name: "Farooq",
language: "JavaScript"
};
const arrVal = [1, 2, 3, 4, 5];
console.log(`
type of numVal: ${typeof (numVal)}
type of stringVal: ${typeof (stringVal)}
type of boolVal: ${typeof (boolVal)}
type of objVal: ${typeof (objVal)}
type of arrVal: ${typeof (arrVal)}`
)
// Activity 4 : Reassiging variables
// Task 5: Declare a variable using let, assign it an initial value, reassign a new value, and log both values to the console.assert
let msg = "Good Morning";
msg = "Good Night"
console.log(msg)
// Activity 5: Understanding const
// Task 6: Try reassigning a variable declared wit const and observe the error
const memories = "school life is best"
// memories = "college life is best"
// console.log(memories) //TypeError: Assignment to constant variable.
// Overall Output
/*10
Farooq
JavaScript
type of numVal: number
type of stringVal: string
type of boolVal: boolean
type of objVal: object
type of arrVal: object
Good Night*/