If I have the following code in Javascript:
import getTranslation from "some-library";
import getUserSettings from "some-other-library";
const getTranslatedLabel = () => {
const translatedLabel = getTranslation("cheeseburger");
const { enableTranslatedLabels } = getUserSettings();
if (enableTranslatedLabels) {
return translatedLabel;
} else {
return "";
}
}
Is a javascript engine like V8 smart enough to only execute the getTranslation
function if enableTranslatedLabels is true
?
2
Answers
This has nothing to do with V8 and more to do with your business logic.
You need to rearrange your code so you will execute the function only when enabled.
As other say thats requieres your "logic condition",
because JS is a interpreted language.
That’s how you can operate with special combination of
using && (Short-Circuit) and || (Short-Circuit)