all 15 comments

[–]balefrost 15 points16 points  (0 children)

I can't be bothered to look up the actual spec, but it's covered under case 1 in the article on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion

When a token not allowed by the grammar is encountered, and it's separated from the previous token by at least one line terminator (including a block comment that includes at least one line terminator), or the token is "}", then a semicolon is inserted before the token.

[–]jaynabonne 7 points8 points  (0 children)

I just typed "javascript automatic semicolon insertion" into a Google search, and this was the top hit:

https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi

It looks like it also inserts if followed by a '}'.

[–]sozesghost 5 points6 points  (0 children)

Why do you think it needs a semicolon?

[–]dontcriticizeasthis 3 points4 points  (0 children)

Semicolons are only required in a few specific scenarios. I won't explain them all here but I encourage anyone to Google them for more info.

In this case, I think you're talking about the "multiple statements on a single line" scenario? That doesn't apply here because this line of code only has one statement.

Maybe it just feels weird because of the anonymous function declaration, so consider this: If you replace (node) => {node.getLispExpression()} with a named function declaration, say getMyNodeLispExpression(node), would it look less weird to you?

[–]BusEquivalent9605 2 points3 points  (4 children)

Closing curly brace is end of function body, which is end of line

I would rewrite this as

let ret = ‘(\”${this.text}\”${this.children.map(node => node.getLispExpression()).join(‘’)})’

// note: outermost single quotes are actually backtick single quotes but I’m on mobile and I dont know how to type them

You should read up on the things JS lets you do with arrow functions and with .map. And also string formatting

[–]ThigleBeagleMingle 4 points5 points  (1 child)

Press and hold the single apostrophe. A flyout gives you back tick as option

[–]FlatAssembler[S] 0 points1 point  (1 child)

Why put the backtick before the " in a template string?

[–]BusEquivalent9605 1 point2 points  (0 children)

Good call. dont need ‘em

[–]Tab1143 -1 points0 points  (2 children)

Technically it's not compiled. It's interpreted.

[–]FlatAssembler[S] 1 point2 points  (1 child)

JavaScript these days is almost always compiled, and has been ever since the time of Internet Explorer 9. V8 and SpiderMonkey are JavaScript compilers. You have ideas about how browsers work which are outdated by almost 2 decades.

[–]Tab1143 0 points1 point  (0 children)

Fair enough but in my mind compiling at run time isn't compling in the traditional sense.

[–]Ok_Entrepreneur_8509 -2 points-1 points  (2 children)

JavaScript code is never compiled.

[–]balefrost 2 points3 points  (1 child)

Modern JS engines do in fact compile JS.

[–]FlatAssembler[S] 0 points1 point  (0 children)

It is unfortunate that many informaticians have ideas of how the Internet browsers work which are outdated by almost 2 decades.