Which is better to write the conditional branch, the caller or the caller?

Asked 1 years ago, Updated 1 years ago, 299 views

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.

javascript

2022-12-02 23:45

1 Answers

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.


2022-12-03 07:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.