I don't see this often, is this bad practice? [closed]
up vote
-2
down vote
favorite
I usually see the following:
if (true) myFunc();
However my colleague uses: true && myFunc();
Is there anything wrong with the second approach?
javascript
closed as primarily opinion-based by Dekel, Bhojendra Rauniyar, epascarello, Hackerman, Daniel A. White Nov 19 at 15:19
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
up vote
-2
down vote
favorite
I usually see the following:
if (true) myFunc();
However my colleague uses: true && myFunc();
Is there anything wrong with the second approach?
javascript
closed as primarily opinion-based by Dekel, Bhojendra Rauniyar, epascarello, Hackerman, Daniel A. White Nov 19 at 15:19
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
2
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
then only alwaysif
part going to execute and never goes to theelse
part
– mbharanidharan88
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
2
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24
|
show 2 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I usually see the following:
if (true) myFunc();
However my colleague uses: true && myFunc();
Is there anything wrong with the second approach?
javascript
I usually see the following:
if (true) myFunc();
However my colleague uses: true && myFunc();
Is there anything wrong with the second approach?
javascript
javascript
asked Nov 19 at 15:18
Jack Holmes
736
736
closed as primarily opinion-based by Dekel, Bhojendra Rauniyar, epascarello, Hackerman, Daniel A. White Nov 19 at 15:19
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as primarily opinion-based by Dekel, Bhojendra Rauniyar, epascarello, Hackerman, Daniel A. White Nov 19 at 15:19
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
2
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
then only alwaysif
part going to execute and never goes to theelse
part
– mbharanidharan88
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
2
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24
|
show 2 more comments
2
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
then only alwaysif
part going to execute and never goes to theelse
part
– mbharanidharan88
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
2
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24
2
2
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
then only always
if
part going to execute and never goes to the else
part– mbharanidharan88
Nov 19 at 15:19
then only always
if
part going to execute and never goes to the else
part– mbharanidharan88
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
2
2
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
Not really. However I find the first one more readable.
– Kristjan Kica
Nov 19 at 15:19
They do the same thing. Some people like to type less.
– epascarello
Nov 19 at 15:19
then only always
if
part going to execute and never goes to theelse
part– mbharanidharan88
Nov 19 at 15:19
No. It's not bad practice. But it's just a shorthand method where you'll use for short case.
– Bhojendra Rauniyar
Nov 19 at 15:19
2
What it returns is not even used so does not even matter
– epascarello
Nov 19 at 15:24