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
  • 22,220
  • 38
  • 99
  • 171

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
  • 24,184
  • 7
  • 51
  • 67