0

i would expect a TRUE, why do i get FALSE?

   var words = ['Hi', 'Hello', 'Good day'];  
    var otherWords = [...words];  
    console.log(otherWords);           // => ['Hi', 'Hello', 'Good day']  
    console.log(otherWords === words); // => false  
Grumpy
  • 2,140
  • 1
  • 25
  • 38
  • 4
    Because they're different arrays. Equivalent, but different. – T.J. Crowder Dec 02 '16 at 08:35
  • i cant find the question – Grumpy Dec 02 '16 at 08:37
  • What do you mean? The link is right there. (Did you mean "couldn't"?) – T.J. Crowder Dec 02 '16 at 08:38
  • @T.J.Crowder, the dupe does not answer the function of the [spread syntax `...`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator) and the generating a of new array literal. – Nina Scholz Dec 02 '16 at 08:38
  • 1
    @NinaScholz: How the array was created is irrelevant. The crux here is that the comparison is flawed. The OP even knows that he/she is dealing with separate arrays, from their use of the word "clone." (But because the array creation was different, I posted the comment above, to help the OP understand why that was the relevant bit.) – T.J. Crowder Dec 02 '16 at 08:39
  • @crowder, sorry, i meant couldn't – Grumpy Dec 02 '16 at 15:34
  • @T.J.Crowder the mentioned question does not answer my question. The array is cloned but not equal, why? – Grumpy Dec 02 '16 at 15:39
  • @Grumpy: Yes, it does. When you close an array, you create a new, separate array, right? `===` isn't how you check two separate arrays to see if they have the same contents, as the linked question's answers explain. – T.J. Crowder Dec 02 '16 at 15:44

0 Answers0