1
let { length } = "hello app"
console.log(length) //=> 9

why the output of console.log is 9(it seems like string's length)? Actually, I can't understand the syntax of first line.

omgdog
  • 61
  • 1
  • 4
  • That is [destructuring syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) – Patrick Evans Sep 26 '18 at 06:35
  • @PatrickEvans Yeah but destructuring works with objects isn't it so bit more explanation why it works also with primitive types which string literal is would be nicer I believe. – Giorgi Moniava Sep 26 '18 at 06:37
  • 1
    Strings are also objects, objects with a length property that you can destructure. So when you destructure a string this way, it's identical to `let length = "hello app".length;` – Shilly Sep 26 '18 at 06:45

0 Answers0