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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With