i got error for removing the semi colon

i got error for removing the semi colon
31 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Mark
MarkOP2w ago
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Mark
MarkOP2w ago
im just confused lol why it got error for removing semi colon
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Mark
MarkOP2w ago
thank you i thought it was necessary
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Mark
MarkOP2w ago
how do u know if its required
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Mark
MarkOP2w ago
oh thank you bro this should be not the variable thing
No description
Mark
MarkOP2w ago
hey also bro do u know how do i get autocompletion thing on command files
Amgelo
Amgelo2w ago
you're supposed to put it on the end of the last line, not at the beginning of the next one maybe it works but it's definitely not how you're supposed to do it
aMeow
aMeow2w ago
It’s pretty common to place it at the behinning in codebases not using semicolons Ig immedietely invoked functions are somewhat rare, but you usually see them every now and then (especially before top level await was a thing). It’s also used for a bunch of literals which ig are also kinda rare (eg. [1,2,3].forEach(…) What I’m saying is that, in codebases that don’t use semicolons at the end of every line (I think that’s the default behavior with prettier formatting?), if they need to seperate statements so they don’t turn into non-sense (for IIFE and the literal examples above), it’s pretty common to place the semicolon at the beginning of the row Okii ty, my mistake
veksen
veksen2w ago
if you're new to JS, very much consider using semicolons, and even better use a tool like Prettier that manages them for you. Prettier would handle this edge case knowing you can't do fn() () the JS reasoning is that this would attempt to call a function that's the return of your previous function, for example:
function fn() {
return function () {
console.log("do something..")
}
}

fn()() // logs "do something.."
function fn() {
return function () {
console.log("do something..")
}
}

fn()() // logs "do something.."
Steve
Steve2w ago
Question, I just don't do semicolons, no errors with any of that tho?
duck
duck2w ago
you can write plenty of properly functioning js code with no semicolons, but as showcased above, it sometimes causes issues therefore it's generally recommended just as good practice, even when not necessary if you search in:#djs-help-v14 semicolon in this server, you may find there's quite a few cases of it being necessary
Steve
Steve2w ago
I don't believe in such async statements Thanks anyways
Mark
MarkOP2w ago
u forgot the semi colons same mistake that i made
veksen
veksen2w ago
const rest = new REST().setToken(yourToken)
[...commands].forEach()
const rest = new REST().setToken(yourToken)
[...commands].forEach()
then do read what I said tho: HIGHLY recommend yourself to equip yourself with Prettier and auto insert them (or remove), regardless of the setting you use, Prettier will cover your ass from ASI
Mark
MarkOP2w ago
you made him test it his question is a yes or no answer
Amgelo
Amgelo2w ago
no, his question was a retorical one "I don't do semicolons and there's no issues with that code" so Qjuh said "now test this"
Lyrian
Lyrian2w ago
JavaScript actually needs semicolons. If you dont write them, then ASI (automatic semicolon insertion) comes into play. I believe you are using some prettier (or another formatter) that formats your code, making it not executable. Let me give you an example:
const boo = { value: 0 }
const foo = true
[boo.value] = [1,2,3] // boo.value = 1
const boo = { value: 0 }
const foo = true
[boo.value] = [1,2,3] // boo.value = 1
Prettier will now think that you want to open Line 2 with the [] expression and rewrites your code into
...
const foo = true[boo.value] = [1,2,3]
...
const foo = true[boo.value] = [1,2,3]
which will fail because you can't index a boolean... Edit: I believe in your case the same thing happens but with the () expressions e.g.
const a = 3
(()=>console.log('hi'))()

// will be formatted to
const a = 3(()=>console.log('hi'))
const a = 3
(()=>console.log('hi'))()

// will be formatted to
const a = 3(()=>console.log('hi'))
Lyrian
Lyrian2w ago
No description
Lyrian
Lyrian2w ago
P.S. I just noticed you have no formatter, so it is probably the ASI doing this. There is nothing you can do, this is standard JS.
No description
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Mark
MarkOP2w ago
see my code was right you should put semi colons before the func
Amgelo
Amgelo2w ago
@Mark
Lyrian
Lyrian2w ago
Thank you for letting us now. I appreciate your valuable input. Im pretty sure OP knew (as you did) that his question was not related to discord.js. Lucky that u noticed straight ahead that he was just pretending in his code to use discord.js and knew beforehand that his semicolon question had nuffin to do with discord.js because he obv is a professional developer as you are :yya:
Steve
Steve2w ago
I thought it did that When I get in trouble, I'll change my ways 😭
Lyrian
Lyrian2w ago
No description

Did you find this page helpful?