Node.js v8.15.0 is *super weird* about destructuring assignment, it seems.

Works interactively. Does not work inside a function. What?

Is it a semicolon thing? On the REPL it's just the one line, but in the full file there's a greater risk of confusion.
Follow

@natecull @clacke it is a semicolon thing. the brackets are interpreted as being part of a previous line. putting "const" in front of that destructure (or a semicolon) will solve that issue. one of the few things that will bite you when you don't use semis in JavaScript.

· · SubwayTooter · 2 · 0 · 1

@natecull @clacke (sorry for the second ping, took me a minute to track down this article, but) blog.izs.me/2010/12/an-open-le is a good overview. I don't use semicolons either, but there are a few things to watch out for!

@fardog @natecull Right! Because the coder could have written something like [x, ... xs] = thing.do_stuff()[42] and therefore the parser has already decided that semicolon insertion is not necessary here, this'll make sense without it. And then it doesn't.
Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!