Else If ends with Else JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Else If ends with Else JavaScript

Does an else of have to end with else or can it just end with the brackets?

21st Jul 2019, 10:28 AM
Timemaster111
Timemaster111 - avatar
4 Answers
+ 3
As far as i know it doesnt make a difference (your code is still valid) but if you for example check if something is null (object) it's better to throw an error. That's why the JS course suggested else statements.
21st Jul 2019, 10:38 AM
TheTJO
TheTJO - avatar
+ 3
Can you please specifiy your language and your problem +code a little bit deeper so we can give you a detailed answer.
21st Jul 2019, 10:31 AM
TheTJO
TheTJO - avatar
+ 3
Generally speaken: in most (all i know) languages an IF statement can end only with brackets not eith an additional else statement
21st Jul 2019, 10:32 AM
TheTJO
TheTJO - avatar
+ 1
thanks, thats what i thought too but the javascript tutorial suggested otherwise. thank yiu for the help.
21st Jul 2019, 10:35 AM
Timemaster111
Timemaster111 - avatar