Suppose you have two JavaScript codes:
Except for fine performance, both should get the same output.
The difference is that if the variable isMorning is true, call the function morningGreeting() or the function morningGreeting() always calls and branches within it.
if(isMorning) morningGreeting();
function morningGreeting(){
console.log('Good morning!');
}
morningGreeting();
function morningGreeting(){
if(isMorning) return;
console.log('Good morning!');
}
In general, which code is better in terms of serviceability and readability?
Some people may say that it doesn't matter as long as the project is unified.
I'd like to hear your opinion.
console.log('Good morning!'); I think running
depends on whether isMorning
is false or not.
If this is the case, I think it would be better to run it in function in terms of module strength.
© 2024 OneMinuteCode. All rights reserved.