Introduction to JavaScript

JavaScript code on a screen

Degui Adil/EyeEm/Getty Images

JavaScript is a programming language used to make web pages 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, it has likely been produced by JavaScript.

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 Android apps, enterprise systems that move large amounts of data (especially in the finance industry), and embedded functions for "Internet of Things" technologies (IoT).

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

What makes JavaScript great is that it's not necessary to know how to write it to use it in your web code. You can find plenty of prewritten JavaScripts for free online. To use such scripts, all you need to know is how to paste the supplied code into the right places on your web page.

Despite the easy access to prewritten scripts, many coders prefer knowing how to do it themselves. Because it is an interpreted language, 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 complementary languages. 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 accessible if placed them in separate files (using a .JS extension helps identify them). You then link the JavaScript to your HTML by inserting a tag. That 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.

Format
mla apa chicago
Your Citation
Chapman, Stephen. "Introduction to JavaScript." ThoughtCo, Feb. 16, 2021, thoughtco.com/what-is-javascript-2037921. Chapman, Stephen. (2021, February 16). Introduction to JavaScript. Retrieved from https://www.thoughtco.com/what-is-javascript-2037921 Chapman, Stephen. "Introduction to JavaScript." ThoughtCo. https://www.thoughtco.com/what-is-javascript-2037921 (accessed December 29, 2024).