What does || {} means in JavaScript?

javascript

Solution

This means that if `window.google` doesn't have value `(undefined, null)` then use `{}`.

It is a way of assigning a default value to a variable in JavaScript.

Problem

I am confused with this code that I found in the Google Maps API: ``` window.google = window.google || {}; google.maps = google.maps || {}; ``` And other code that I saw in a book: ``` var QQ = QQ || {}; ``` What does it mean? Why should we print that code at beginning of the JavaScript file?

Original source

Related problems