Weird Javascript Code Convention With "const"
What is this code convention in javascript? const { navigate } = //whatever As in, what sense does it make. I saw it in RNs React navigation https://reactnavigation.org/docs/intro
Solution 1:
It's named destructuring. When you have an object and you want to take only a property of that object, you can get only it by using that convention.
let fullName = {
first: 'John',
last: 'Smith'
}
const { first } = fullName;
You can take a look here for more info's
http://wesbos.com/destructuring-renaming/
Solution 2:
It's called destructuring
Example:
var myObject = {a: "what", b: "ever"};
const {a} = myObject;
console.log(a); // will give "what"
Post a Comment for "Weird Javascript Code Convention With "const""