WHAT JAVA SCRIPT DOES !
Store useful values inside variables. In the above example for instance, we ask for a new name to be entered then store that name in a variable called
Operations on pieces of text (known as “strings” in programming). In the above example we take the string “Player 1: “ and join it to the
namevariable to create the complete text label, e.g. ''Player 1: Chris".
Running code in response to certain events occurring on a web page. We used aclick event in our example above to detect when the button is clicked and then run the code that updates the text label.
And much more!
APIs are ready-made sets of code building blocks that allow a developer to implement programs that would otherwise be hard or impossible to implement. They do the same thing for programming that ready-made furniture kits do for home building — it is much easier to take ready-cut panels and screw them together to make a bookshelf than it is to work out the design yourself, go and find the correct wood, cut all the panels to the right size and shape, find the correct-sized screws, and then put them together to make a bookshelf.
They generally fall into two categories.
Browser APIs are built into your web browser, and are able to expose data from the surrounding computer environment, or do useful complex things. For example:
The DOM (Document Object Model) API allows you to manipulate HTML and CSS, creating, removing and changing HTML, dynamically applying new styles to your page, etc. Every time you see a popup window appear on a page, or some new content displayed (as we saw above in our simple demo) for example, that's the DOM in action.
The Geolocation API retrieves geographical information. This is how Google Maps is able to find your location and plot it on a map.
Audio and Video APIs like
WebRTCallow you to do really interesting things with multimedia, such as play audio and video right in a web page, or grab video from your web camera and display it on someone else's computer (try our simple Snapshot demo to get the idea).
Third party APIs are not built into the browser by default, and you generally have to grab their code and information from somewhere on the Web. For example:
The Twitter API allows you to do things like displaying your latest tweets on your website.
eBay - The Company which a web app 50x faster by switching programming languages Where JAVA SCRIPT played a main Role
By compiling code to WebAssembly, developers can build apps that deliver consistently high-performance in the web browser, similar to that offered by apps running natively.
eBay was keen to exploit that performance for a web version of its barcode scanner, a feature it offers in its Android and iOS apps to allow sellers to scan items they are auctioning.
“WebAssembly was different. It has tremendous potential, we just did not have the right use case. Well, that changed recently,” said the eBay software engineering team in an eBay blog post.
One of the advantages of WebAssembly (Wasm) is that it offers code portability for a variety of languages, allowing developers to take code they’ve written for other platforms and compile to WebAssembly so it can run in major web browsers.
Consequently, eBay was able to take the existing version of its barcode scanner written in C++ and compile that to Wasm using Emscripten, adopting the Docker and Node.js-based approach outlined here.
The problem was the Wasm-based scanner was still unable to detect barcodes in 40% of cases.
The team were initially puzzled why the same C++ code that worked in about 100% of cases when compiled to native code for Android and iOS apps was failing when compiled to Wasm to run in the browser. It eventually emerged that these native apps were able to bypass problems with image quality using platform-specific APIs that allowed for autofocus and other features.
The structure of the final web-based barcode scanner.
Only by running all three side-by-side in separate web worker threads, and having each attempt to read the barcode, was the scanner web app able to handle close to 100% of barcodes.
“To our surprise, with three threads racing against each other, the success rate was indeed close to 100%. This again was totally unexpected,” write the team.
The final web-based barcode scanner also proved to be a success with customers during an A/B test, leading to a 30% increase in eBay users who completed the process of listing an item for auction on the site.
“Technology evolves at a very rapid pace. Every day we hear new things getting launched. But only a few make a difference to customers, and WebAssembly is one of them,” the team said.
THANKS FOR WATCHING