Skip to content

Commit

Permalink
add example nullish coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanuelQuintino committed Dec 7, 2023
1 parent 7344120 commit 9b268b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 15 additions & 0 deletions 5-JavaScript/class-02-operators/4-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ console.log("0" ? "true" : "false");
console.log({} ? "true" : "false");
console.log(null ? "true" : "false");
console.log(-Infinity ? "true" : "false");

// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing

// Nullish Coalescing Operator
console.log("Emanuel" || "right-hand");
console.log(1 || "right-hand");

console.log("" || "right-hand");
console.log(0 || "right-hand");

console.log("" ?? "right-hand");
console.log(0 ?? "right-hand");

console.log(null ?? "right-hand");
console.log(undefined ?? "right-hand");
3 changes: 1 addition & 2 deletions 5-JavaScript/class-02-operators/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Class 02 Expressions and Operators</title>
<!-- Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators -->
</head>
<body>
<script src="5-precedence.js"></script>
<script src="4-types.js"></script>
</body>
</html>

0 comments on commit 9b268b1

Please sign in to comment.