0

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/

Kevin Barasa
  • 71
  • 1
  • 10

2 Answers2

2

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/

Alex
  • 166
  • 8
0

It's called destructuring

Example:

var myObject = {a: "what", b: "ever"};
const {a} = myObject;
console.log(a);       // will give "what"
devnull69
  • 16,402
  • 8
  • 50
  • 61