This is the logical OR operator in JS (and most other languages). It is defined in the spec at 11.11. As noted in the spec, expressions on either side will be evaluated first and the logical OR is left-to-right associative. Note that evaluation of the operands follows standard ToBoolean semantics from section 9.2, so [null, undefined, 0, '']
all count as falsy.
Unlike most languages, JS returns the left operand if it is truthy or the right operand otherwise. This behavior has been covered before in a number of SO questions, but is worth noting as most languages simply return true or false. This behavior is often used to provide default values to otherwise undefined variables.
Related Posts:
- What does “javascript:void(0)” mean?
- For-each over an array in JavaScript
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How can I remove a specific item from an array?
- require is not defined? Node.js
- What is NODE_ENV and how to use it in Express?
- function updateMap for Google Maps API
- Loop inside React JSX
- Encode URL in JavaScript?
- JavaScript null check
- JavaScript “Uncaught TypeError: object is not a function” associativity question
- Angular: mat-form-field must contain a MatFormFieldControl
- Module not found can’t resolve
- How can I get file extensions with JavaScript?
- How to detect Safari, Chrome, IE, Firefox and Opera browser?
- What does on() in JavaScript do?
- AngularJS : Factory and Service?
- What’s the difference between console.dir and console.log?
- Use images like checkboxes
- What is the difference between document.location.href and document.location?
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Preloading images with JavaScript
- Javascript Uncaught TypeError : .split is not a function
- Uncaught TypeError: Cannot read property ‘msie’ of undefined
- How to hide a div with jQuery?v
- How do I pass variables and data from PHP to JavaScript?
- How do I set/unset a cookie with jQuery?
- Calling onclick on a radiobutton list using javascript
- How to properly export an ES6 class in Node 4?
- Uncaught Typeerror: cannot read property ‘innerHTML’ of null
- Sorting HTML table with JavaScript
- Relation between CommonJS, AMD and RequireJS?
- How to loop through an array containing objects and access their properties
- Why is the jquery script not working?
- JQuery Datatables : Cannot read property ‘aDataSort’ of undefined
- includes() not working in all browsers
- Why does JSHint throw a warning if I am using const?
- Uncaught TypeError: .indexOf is not a function
- Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array
- How to set onClick with JavaScript?
- How does += (plus equal) work?
- Javascript Comparison Operators != vs !==
- How to get current date in jQuery?
- Print the contents of a DIV
- Remove all special characters except space from a string using JavaScript
- How to Scroll Down – JQuery
- How can I use webpack with express?
- JavaScript check if variable exists (is defined/initialized)
- Embedding instagram webpage inside an iframe
- Do something if screen width is less than 960 px
- Highlight a word with jQuery
- Javascript: ‘window’ is not defined
- Javascript – Replace html using innerHTML
- Syntax error: Illegal return statement in JavaScript
- Error: TypeError: $(…).dialog is not a function
- How do I handle newlines in JSON?
- Update style of a component onScroll in React.js
- Fire oninput event with jQuery
- javascript includes() case insensitive
- Reading local text file into a JavaScript array
- “NS_ERROR_DOM_BAD_URI: Access to restricted URI denied”
- How can I unset a JavaScript variable?
- D3.js: what is ‘g’ in .append(“g”) D3.js code?
- Correct modification of state arrays in React.js
- Angular 2 Sort table columns
- JavaScript string encryption and decryption?
- How to dequeue a script?
- Reset Undo on the tinymce editor
- Combine enqueue js without affecting dependencies
- WP Customizer set a value via javascript (to create presets)
- JavaScript in page doesn’t open new window [closed]
- preserve url parameters from affliliate sites
- wp_enqueue_script adds only the first script
- Add javascript to a woocommerce page template
- Dynamically insert values in a WordPress SelectControl Options field
- Vimeo froogaloop
- What javascript libs & frameworks are integrated in WordPress vanilla?
- Conditional fields in contact form 7 not working
- can a buttongroup have a label?
- Preloader for a WordPress Site
- Trying to integrate Zoho Campaign Form [closed]
- Enqueueing a script and a style sheet not working
- InnerBlocks restricting does not work on nested blocks
- Uppload image from another source wp.media
- Use onfocus event in Contact Form 7
- Get Block Attributes in JSON REST API
- How to open the add media dialogue it in a certain state / tab?
- Removing auto versioning of JS and loading to header
- enqueue script won’t work (enqueue style does work)
- Putting custom html/js page into Elementor as it’s own block
- How to get file object from file_attachment?
- Drag-to-Scroll Landingpage
- Easiest way to find JS conflicts
- How do I load urls from an external .js file to my admin head?
- Nothing in dashboard that uses javascript works
- XMLHttpRequest of admin data to public
- How to execute WP shortcode in a javascript string “”
- Loaded JavaScript file not showing [duplicate]
- PHP or JS for header image rotator?
- Replacing & in JS code on pages