Script – 13-35 Jan 19
I have this code which is supposed to return
lonely integers(the one that occurs once in the array)
It works perfectly but hacker rank keeps rejecting it and I'm not really sure why
This is the error I get![](https://cdn.answeroverflow.com/933354001657921536/unknown.png)
![](https://cdn.answeroverflow.com/933354001917939712/unknown.png)
16 Replies
you have undeclared
i
variable
in strict mode that's error
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#converting_mistakes_into_errorsohhh
I defined i now and it works
is it recommended to define i?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
you ask about variable name or the fact of declaring a variable? For name, it's up to you - the clue is to name variable according to it's usage context so it will be easy for any dev to know what's used for. For not declaring variables - it's a risky thing and works only in non-strict mode (which is less and less present these days, because it's automatically turned on in ESM modules and
Class
es)noted
I meant declaring variable in for loops
yhhh
thanks ![catjam](https://cdn.discordapp.com/emojis/766674394285735947.gif)
![catjam](https://cdn.discordapp.com/emojis/766674394285735947.gif)
you don't have do declare variable in the loop, you can declare it outside the loop - it depends on use case. But still, it's a good practice (and must have in strict mode) to declare all variables
roger that
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
my linter didnt<:emoji_21:773183935264849930>
do u mean without using strict mode?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
sheesh
I just discovered I do not have any js linter
just the one built-in vs code
which one do u recommend
I see
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh I have that
<:emoji_21:773183935264849930>
nah
just vanilla js
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
<:roger_okay:932725392098349157>