0

Can someone explain how the following if statement works. Inside the if statement there is a test for function addFieldToText, and its arguments. After this line the script jumps into the addFieldToText function

 if(!addFieldToText(refworksFieldMappingEntry.enterpriseCode, refworksFieldMappingEntry))

Is it basically saying if this function has not been called yet, then call it? Hope this makes sense.

1 Answer 1

1

As soon as that if statement is encountered, it:

  • Calls the addFieldToText function passing refworksFieldMappingEntry.enterpriseCode, refworksFieldMappingEntry as arguments.
  • If addFieldToText returns false based on those arguments value, then the if statement is executed.

If the addFieldToText was not prefixed with ! (NOT operator) then addFieldToText would have to return a truthy value for the if statement to execute.

Here's a simplified example:

const isNumberDivisibleBy2 = (num) => {
  return num % 2 === 0
}

if (!isNumberDivisibleBy2(9)) {
  console.log('number is NOT divisible by 2')
} else {
  console.log('number is divisible by 2')
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.