What is the difference between React Native and React?

ReactJS is a JavaScript library, supporting both front-end web and being run on a server, for building user interfaces and web applications. It follows the concept of reusable components. React Native is a mobile framework that makes use of the JavaScript engine available on the host, allowing you to build mobile applications for different platforms … Read more

Loop through an array in JavaScript

Yes, assuming your implementation includes the for…of feature introduced in ECMAScript 2015 (the “Harmony” release)… which is a pretty safe assumption these days. It works like this: Or better yet, since ECMAScript 2015 also provides block-scoped variables: (The variable s is different on each iteration, but can still be declared const inside the loop body as long as it isn’t modified there.) A … Read more

Cross-Origin Read Blocking (CORB)

I have called third party API using Jquery AJAX. I am getting following error in console: Cross-Origin Read Blocking (CORB) blocked cross-origin response MY URL with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details. I have used following code for Ajax call : When I checked in Fiddler, I have got the data in response … Read more

“SyntaxError: Unexpected token < in JSON at position 0"

The wording of the error message corresponds to what you get from Google Chrome when you run JSON.parse(‘<…’). I know you said the server is setting Content-Type:application/json, but I am led to believe the response body is actually HTML. Feed.js:94 undefined “parsererror” “SyntaxError: Unexpected token < in JSON at position 0” with the line console.error(this.props.url, … Read more

Define a global variable in a JavaScript function

As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable: (Note that that’s only true at global scope. If that code were in a module — <script type=”module”>…</script> — it wouldn’t be at global scope, so that wouldn’t create a global.) Alternatively: In modern … Read more

How to replace all occurrences of a string in JavaScript

Update: In the latest versions of most popular browsers, you can use replaceAll as shown here: But check Can I use or another compatibility table first to make sure the browsers you’re targeting have added support for it first. For Node and compatibility with older/non-current browsers: Note: Don’t use the following solution in performance critical … Read more

How does Access-Control-Allow-Origin header work?

Access-Control-Allow-Origin is a CORS (Cross-Origin Resource Sharing) header. When Site A tries to fetch content from Site B, Site B can send an Access-Control-Allow-Origin response header to tell the browser that the content of this page is accessible to certain origins. (An origin is a domain, plus a scheme and port number.) By default, Site … Read more