XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header

tl;dr — There’s a summary at the end and headings in the answer to make it easier to find the relevant parts. Reading everything is recommended though as it provides useful background for understanding the why that makes seeing how the how applies in different circumstances easier. About the Same Origin Policy This is the Same Origin Policy. It is a … Read more

Uncaught ReferenceError: google is not defined when trying to use Google Places API without a map

From my reading, async and defer aren’t meant to be used at the same time. While your <script> that loads the API from google is deferred, your <script> with your code is not deferred. (If you remove async and defer your code works, but is theoretically slower.) If you defer your code execution until the document is loaded (and the google api instantiated), then your code should … Read more

Why is “forEach not a function” for this object?

bject does not have forEach, it belongs to Array prototype. If you want to iterate through each key-value pair in the object and take the values. You can do this: Usage note: For an object v = {“cat”:”large”, “dog”: “small”, “bird”: “tiny”};, Object.keys(v) gives you an array of the keys so you get [“cat”,”dog”,”bird”]

What is the difference between document.location.href and document.location?

document.location is a synonym for window.location that has been deprecated for almost as long as JavaScript has existed. Don’t use it. location is a structured object, with properties corresponding to the parts of the URL. location.href is the whole URL in a single string. Assigning a string to either is defined to cause the same kind of navigation, so take your … Read more

HTML5 Local storage vs. Session storage

localStorage and sessionStorage both extend Storage. There is no difference between them except for the intended “non-persistence” of sessionStorage. That is, the data stored in localStorage persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site. For sessionStorage, changes are only available per tab. Changes made are saved and available for the current page in that tab until … Read more