4

Consider the following examples

An old project:

const [x, ...y] = "text";
console.log(x) // "t"
console.log(y) // "ext"

A new project based on CRA:

const [x, ...y] = "text";
console.log(x) // "t"
console.log(y) // ["e", "x", "t"]

I'm not sure why y is returning a string ("ext") for the old project, where it's an array of characters (["e", "x", "t"]) for the new project. Is it something to do with different JS versions?

Note: Both result were extracted after running webpack dev server.

hibecap531
  • 51
  • 4
  • 3
    The second output is the one that the spec would require... (rest params should always create an array, no matter, what was destructured) – FZs Dec 19 '20 at 11:44

1 Answers1

4

in babel website you can see that your code based on es2015-loose convert to this code so output of this code is same with your old project

"use strict";

var _text = "text",
    x = _text[0],
    y = _text.slice(1);

console.log(x); // "t"

console.log(y); // "ext"
barzin.A
  • 1,554
  • 2
  • 12
  • 20