I’m a little confused with the syntax here.
window.foo = window.bar || {};
Any ideas? I’m just trying to understand javaScript better. 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
window.baris null or undefined (also:0,"",NaNandfalse) thenwindow.foowill be set to an empty object ({}), otherwise it will bewindow.bar.The logical OR operator (
||) works as a null coalescing operator in this situation. It’s basically shorthand for:This post explains the behavior in more detail.