0
Is else required in this code
function checkAge(age) { if (age > 18) { return true; } else { return confirm('Did parents allow you?'); } } Will the function work differently if else is removed? function checkAge(age) { if (age > 18) { return true; } return confirm('Did parents allow you?'); }
5 Respostas
+ 3
There are only 2 scenarios.
1) age > 18
If this is true, it returns true.
2) age < 18
If case 1 fails, this is by default true. You don't have to include else because in both case it will exit as soon as it hits the return statement.
+ 3
It is not required because u re using the return keyword which will end the execution anyway otherwise if u were just printing a message the else required to show two different messages
+ 1
Thank you so much TheGirlHasNoName you cleared my doubt.
0
I am looking for bit explained.
0
Thanks Avinesh