0

I am refactoring some javascript code and came across this expression:

false === options.onSubmit.call(this)

What would be the purpose to put the false first? Is there a difference between that expression and this expression?

options.onSubmit.call(this) === false
jhamm
  • 24,124
  • 39
  • 105
  • 179

1 Answers1

2

What I think the best benefit of that is you can't accidentally do assignment instead of compare. It comes in place basically with == check.

When you want to compare two values like bellow

someVariable === false 

OR

someVariable == false 

could be accidently

someVariable = false

But

false = someVariable

Will cause a error ReferenceError: Invalid left-hand side in assignment. So you will get rid of that mistake.

Mritunjay
  • 25,338
  • 7
  • 55
  • 68