Why Can't I Remove The Intermediate Variable In My Code? April 21, 2024 Post a Comment I'm currently working with the spread syntax and ran into an unexpected issue. The below snippet works (as expected), and doesn't throw any errors: However, if I remove the intermSolution 1: Add a semicolon and it works perfectly. const arr = [1, 2, 3, 4]; [...arr].forEach(n => { console.log(n + 1); });CopyThe code was being evaluated without the newline - like this:const arr = [1, 2, 3, 4][...arr] CopyWhich resulted in your error. Share Post a Comment for "Why Can't I Remove The Intermediate Variable In My Code?"
Post a Comment for "Why Can't I Remove The Intermediate Variable In My Code?"