I just took a look at this answer, and I noticed the following line of javascript code:
hrs = (hrs - 12) || 12;
My Question:
What does the ‘||’ operator mean when
used in an assignment?
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.
In this case, the code assigns 12 to hrs if hrs-12 = 0 (as JavaScript sees it, 0 = false).
More generally, it assigns the latter value to the variable if the former value evaluates to 0, the empty string, null, undefined, etc.