Last active
November 2, 2020 15:57
-
-
Save Mahdhir/e7ff3ea73d85ccb913b9ca18e3497f23 to your computer and use it in GitHub Desktop.
Revisions
-
Mahdhir revised this gist
Nov 2, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,5 +28,5 @@ if (book && book.weight && book.weight.version3 && book.weight.version3.value) { } //Accessing without checking console.log(book.weight.version3.value); //error -
Mahdhir created this gist
Oct 1, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ let book = { name: "Harry Potter 1", price: { value: 50, currency: "EUR" }, ISBN: "978-7-7058-9615-2", weight: { version1: { value: 550, unit: 'g' }, version2: { value: 690, unit: 'g' } } } if (book && book.weight && book.weight.version2 && book.weight.version2.value) { //Do something with book.weight.version2.value console.log(book.weight.version2.value); } if (book && book.weight && book.weight.version3 && book.weight.version3.value) { //Since there is no version 3, this block would not run and throw any errors console.log(book.weight.version3.value); } //Accessing without checking console.log(book.weight.version3.value; //error