-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControl Flow in JavaScript.html
More file actions
93 lines (77 loc) · 2.66 KB
/
Control Flow in JavaScript.html
File metadata and controls
93 lines (77 loc) · 2.66 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Control Flow in JavaScript</title>
</head>
<body>
<script>
// *****************IF**********
// === also check data-type
const userLoggedIn = true
const debitCard = true
const loggedInFromeGoogle =false
const LoggedInFromeEmail =true
if(userLoggedIn && debitCard){
console.log("Allow to buy course");
}
if(loggedInFromeGoogle || LoggedInFromeEmail){
console.log("User Logged in");
}
// ******************************* Switch *****************
// switch (key) {
// case value:
// break;
// default:
// break;
// }
const month =Number( prompt("Enetr only a number From 1 to 4"))
switch (month) {
case 1:
console.log("January");
break;
case 2:
console.log("Februry");
break;
case 3:
console.log("March");
break;
case 4:
console.log("April");
break;
default:
console.log("Default Execution");
break;
}
// ***************************Truthi Or Falsy Values ***********************
// ***** flasy values = false, 0 , -0 , BigInt , 0n, Null, undefine , NaN ,""
// ***** Truthi Value = "0" , 'false' , " " ,[] , {} , function(){} empty function
const userEmail = []
if (userEmail){
console.log("Got User Email");
}else {
console.log("Dont have user Eamil");
}
// check the falsy value 0
if(userEmail.length === 0){
console.log("Array is empty");
}
// Check empty Object
const emptyObj ={}
if (Object.keys(emptyObj).length === 0){
console.log("Object is Empty");
}
// ****************************Nullish Coalescing Operator (??) null ,undefined
// Used in special Data Base
let val1
val1 =5 ?? 10 //Or
val1= null ?? 10 //or Also called a flag values
val1 = undefined ?? 15
console.log(val1);
// ***********************************Turnary Operator
const iceTeaPrice =100
iceTeaPrice <= 80 ? console.log("Less then 80") :console.log("More then 80");
</script>
</body>
</html>