jskatas.org Continuously Learn JavaScript. Your Way.

Destructuring: string

Destructuring can also be done on strings.

Destructuring also works on strings

destructure every character, just as if the string was an array
let a, b, c = 'abc'; assert.deepEqual([a, b, c], ['a', 'b', 'c']);
missing characters are undefined
const [a, c] = 'ab'; assert.equal(c, void 0);
unicode character work too
const [space, coffee] = 'a β˜•'; assert.equal(coffee, '\u{2615}');

Required Knowledge

Related Katas

Destructuring

Difficulty Level

BEGINNER

First Published

27 March 2015

Stats

3 tests to solve