-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnullish-coalescing-operator.html
35 lines (28 loc) · 1.04 KB
/
nullish-coalescing-operator.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nullish Coalescing Operator</title>
</head>
<body>
<script>
/*
## Nullish Coalescing Operator
● Nullist value adalah null dan undefined
● Nullist coalescing operator (??) adalah operator mirip dengan ternary operator, yang membedakan adalah pada kondisi, jika bernilai null atau undefined, baru value default nya diambil
*/
let parameter;
let data = parameter;
document.writeln(`<p>=====Tanpa Nullish Coalescing Operator=====</p>`);
if (data === undefined || data === null) {
data = "nilai default";
}
document.writeln(`<p>${data}</p>`);
document.writeln(`<p>=====Dengan Nullish Coalescing Operator=====</p>`);
data = parameter ?? "Nilai Default";
document.writeln(`<p>${data}</p>`);
</script>
</body>
</html>