Back in the days of JSPerf, the object literal lookup was always faster. The difference grows larger as you add more lines of "if" checks.
It's also a helpful & popular pattern to declare your string constants in an all-caps "constant" name (so const passwords would be const PASSWORDS) to consolidate (as opposed to mixing them throughout lines of an if/else statement) and make them easily recognizable. Then the lookup would read PASSWORDS[password.toLowerCase()]. Definitely not a "rule", but helpful to the reader.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Back in the days of JSPerf, the object literal lookup was always faster. The difference grows larger as you add more lines of "if" checks.
It's also a helpful & popular pattern to declare your string constants in an all-caps "constant" name (so
const passwords
would beconst PASSWORDS
) to consolidate (as opposed to mixing them throughout lines of an if/else statement) and make them easily recognizable. Then the lookup would readPASSWORDS[password.toLowerCase()]
. Definitely not a "rule", but helpful to the reader.