A
A
Arthur2016-02-26 13:43:16
Programming
Arthur, 2016-02-26 13:43:16

Number-constant at the beginning of the comparison?

From time to time I come across a style of code (js mostly) that puts a constant number first in comparison constructs, for example:

if ( 5 == var ){
  // операции
}

Does this have a sacred meaning?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Oparin, 2016-02-26
@astralo

The point is that if you write '=' instead of '==', then the option

if ( var  = 5){
  // операции
}

will silently work, but not at all as we would like

O
one pavel, 2016-02-26
@onepavel

This is called yoda style
https://habrahabr.ru/post/111432/
I constantly use it with strings
if someVar is null, then there will be no exception

V
Vladimir, 2016-02-26
@qDiablo

when comparing equality/not equality, no

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question