Introduction to JavaScript

JavaScript
Degui Adil / EyeEm / Getty Images

JavaScript is a programming language used to make webpages interactive. It is what gives a page life—the interactive elements and animation that engage a user. If you've ever used a search box on a home page, checked a live baseball score on a news site, or watched a video, JavaScript is probably running through it.

JavaScript Versus Java

JavaScript and Java are two different computer languages, both developed in 1995.

Java is an object-oriented programming language, which means it can run independently in a machine environment. It is a reliable, versatile language used for apps for Android devices, enterprise systems that move large amounts of data (especially in the finance industry), and embedded functions for Internet of Things technologies (such as a web-enabled thermostat).

JavaScript, on the other hand, is a text-based programming language meant to run as part of a web-based application. When first developed, it was intended to be a compliment to Java. But JavaScript took on a life of its own as one of the three pillars of web development—the other two being HTML and CSS. Unlike Java applications, which need to be compiled before they can run in a web-based environment, JavaScript was purposely designed to integrate into HTML. All major web browsers support JavaScript, though most give users the option of disabling support for it.

Using and Writing JavaScript

The great thing about JavaScript is that you don't need to know how to write it in order to use it in your web code. You can find plenty of prewritten JavaScripts for free online. All you need to know to be able to use such scripts is how to paste the supplied code into the right places on your web page.

Although you don't need to write JavaScript in order to use it, some coders just like knowing how to do it themselves. It is an interpreted language, so no special program is required to create usable code. A plain text editor like Notepad for Windows is all you need to write JavaScript. That said, markdown editor might make the process easier, particularly as the lines of code add up.

HTML Versus JavaScript

HTML and JavaScript are two different things, but they are complementary. HTML is a markup language designed for defining static webpage content. It is what gives a webpage its basic structure. JavaScript is a programming language designed for performing dynamic tasks within that page, like animation or a search box. 

JavaScript is designed to run within the HTML structure of a website and is often used multiple times. If you're writing code, your JavaScript will be more easily accessed if you place them in separate files. (Using a .JS extension helps identify them.) You then link the JavaScript to your HTML by inserting a tag. The same script can then be added to several pages just by adding the appropriate tag into each of the pages to set up the link.

PHP Versus JavaScript

PHP is a server-side language that is designed to work with the web by facilitating data transfer from server to application and back again.

Content management systems like Drupal or WordPress use PHP, allowing a user to write an article that is then stored in a database and published online.

PHP is by far the most common server-side language used for web applications, although its future dominance may be challenged by Node.jp, a version of JavaScript that can run on the back end like PHP but is more streamlined.