Is there any short syntax or trick to write such as in code below?
if (!obj.prop) {
obj.prop = value;
}
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.
maybe
but be aware that if
obj.propis a falsy value, it will get set tovalue.Perhaps you want to test to see if the property is defined for
obj