Last active
May 13, 2020 21:00
-
-
Save ramazankanbur/a892f8cbd7335f29f4ce4d08be04e767 to your computer and use it in GitHub Desktop.
This file contains 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 characters
//ES5 | |
var obj = { a: 1 }; | |
var list = [1]; | |
var a = obj.a; | |
var b = obj.b === undefined ? 2 : obj.b; | |
var x = list[0]; | |
var y = list[1] === undefined ? 2 : list[1]; | |
console.log(a, b, x, y); | |
//output | |
//1 2 1 2 | |
//ES6 | |
var obj = { a: 1 }; | |
var list = [1]; | |
//Eğer obj içinde b değeri tanımlanırsa o değer değişkene atanır yoksa 2 olarak ayarlanır | |
var { a, b = 2 } = obj; | |
//Eğer list içinde 2. eleman olursa y'nin değeri 2. eleman olarak ayarlanır yoksa 2 olarak ayarlanır | |
var [x, y = 2] = list; | |
console.log(a, b, x, y); | |
//output | |
//1 2 1 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment