+ 1
Javascript doubt
Because this code has output: 10 let{log} = console; log("10");
2 ответов
+ 6
Brayan Pinilla look that code like this:
let log = console.log;
log("10");
Mira el código así:
let log = console.log;
log("10");
let {log} = console Primero verifica si console tiene una propiedad log(un método en este caso) y luego asigna esa propiedad a una variable let log.
+ 2
Destructuring assignment is a ES6 syntax.
console.log is the log method on the console object.
With { } in assignment, it detaches the method from console object.
You can even rename the method in object destructuring, like this:
https://code.sololearn.com/WrdB29dw8NxT/?ref=app
You can find more about it in Morpheus's JS Fact #050
https://www.sololearn.com/post/45092/?ref=app
You can find the whole Morpheus's JS Fact here :
https://code.sololearn.com/Wyr76080kKxS/?ref=app