I have a syntax issue, let's say I have the following function. He received the text to check spelling and returned the correct text, or false if the text was already spelled correctly.
var spellCheck = function (txt) {
var spelledTxt = spell(txt);
if (spelledTxt =! txt) {
return spelledTxt;
}
return false;
}
Now in another function I want to call this function from the ElseIf instruction, and I want to get into this instruction only if there was a typo in the text that was corrected. sort of:
if(something){
do something....
}else if(spellCheck(word)){
do something with the spelledTxt that was returned from "spellcheck"
}
Can I just do:
else if(var spelledWord = spellCheck(word))
do something with spelledWord.
I forgot a very important thing: spellCheck(word)- a very heavy function, and I would like to avoid the call, if not needed. This means that only if we come to else if(), it will be called, not earlier.
source
share