What is JavaScript?

JavaScript is a programming or scripting language that makes it possible to include some complex features on a web page. Whenever you see anything on a web page that is more active than simple text, it’s a good bet that JS is behind it all, because it is superior for developing animated graphics, interactive maps, content updates, and even for scrolling music playlists. JavaScript is the third essential layer of standard web technologies, the other two being the HTML coding language, and Cascading Style Sheets (CSS).

The three standard web technologies  

HTML is short for Hypertext Markup Language, and it is used to provide structure for the content you see on any web page. For instance, it highlights new paragraphs, headings, or tables, and it can help you to embed items or files on any web page you’re developing.

Cascading style sheets provide the rules and utilities necessary for adding style and design to content, for instance, adding color to backgrounds and formatting content in one or multiple columns for easier reading.

JavaScript is a coding language that makes it possible to include dynamic information, animate your images, control multimedia programs, and a great deal more. These three building blocks of web technology make development of web pages much easier, and it makes the results much more appealing and engaging.

What can JS really do?

It is possible to accomplish a great many programming tasks using JavaScript, many of which are done in response to user actions and are therefore dynamically prepared by JS. As one example, you can use it like a traditional coding language to store values inside variables for later usage. You can then build on that by operating on a string and joining the variable value to an existing string, so as to come up with an entirely new, and dynamic, string.

Where JS really excels though, and one of the reasons it is used for so many development tasks, is its ability to execute prepared code in response to some action taken on a web page. One of the most common types of events is a ‘click’ event, i.e. when a user has clicked on a button or some other item on a web page. Detecting this click, JS would then run a prepared body of code that accomplishes a desired task.

The power of JavaScript can be increased tremendously when you make use of the functionality which is built on top of the client-side version of JS, and that means using Application Programming Interfaces (APIs). When APIs are integrated with JS, it has the effect of turbo-charging your JavaScript code and giving it superpowers that are far beyond its basic capabilities.

APIs themselves are canned programs that allow you to accomplish some complex tasks that might otherwise not be achievable. Programs like these are developed to accomplish some predictable computing tasks, and they can be called whenever needed to perform their function and then go back into a rest state.

These programs fall into two general categories, those being browser APIs and third-party APIs. Browser APIs are built into your computer’s browser, and they are helpful for exposing certain elements of the computer environment itself, or for performing some complex tasks associated with it. Third-party APIs are not included in the browser, and so must be obtained from somewhere else in your environment.

What JavaScript does on a web page

When you load any web page into your browser, you are actually running HTML, CSS, and JavaScript in a browser tab, which is your execution environment. One very common usage of JS is to dynamically alter the CSS and HTML so as to update the interface for a user.

Since code is generally loaded then executed in the same order it appears on the web page, it will be possible for errors to occur, especially when JavaScript gets loaded before the CSS and HTML which it is intended to operate on. Whenever your browser encounters some JS code, it will attempt to run it from top to bottom, so care must be taken with the code to ensure that the order of execution is correct.

JavaScript is considered an interpreted language, as opposed to one that’s compiled. Compiled languages are converted into binary code before being executed, one good example of which is the C++ language. Interpreted languages are run by a browser in their original text form and are not compiled ahead of time.

Modern JS actually undergoes a process called just-in-time compiling, which does convert it to binary prior to execution, but this happens right at execution time rather than being pre-compiled like C++. For that reason, JavaScript is still considered to be an interpreted language.

Client-side usage of JavaScript

You might be surprised to learn that 98% of all websites make use of JS for client-side functions. JS packets are either embedded in HTML or included in HTML files so they can interact with the Document Object Model (DOM). The DOM is the entire HTML document that gets loaded into your browser and can be operated on by your JS code. All browsers have a JavaScript engine that allows them to execute JS code on your client machine.

Some of the more common uses of JS on the client side include playing browser video games, the generation of pop-up ads, redirecting a user to another page, sending data about user behavior to a server, loading new web page content without re-loading the page itself, controlling the display of streaming media, and fading objects in and out or re-sizing them.

Since the usage of JS is so widespread, it has become a frequent target for hackers and the criminal-minded element among computer users. However, a couple of fundamental restrictions prevent most attempts at hacking or corruption. The first restriction limits users to running web-related functions, rather than general purpose tasks like creating or deleting files.

The second restriction is referred to as the same-origin policy, and it ensures that scripts run in one environment have no access to scripts or information run in any other environment. If there are ever breaches made against JavaScript code, it will almost always involve violations of one of these two restrictive policies.

Press ESC to close