Javascript code:
var a = (b) ? b : 40;
It is working, just NetBeans says: “Use the || operator (Column [where the ? is])”. I didn’t find any explanation.
What is it?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are just testing for the truthyness of
bthen you can do this:… which is shorter and (arguably) more obvious. In JavaScript,
||is a short circuit operator. It returns the left hand side if it is true, otherwise it returns the right hand side. (i.e. it doesn’t return a boolean unless the input was a boolean).If you want to see if
bis actually defined, then you are better off with: