JavaScript

Updated: 03/10/2024 by Computer Hope
JavaScript or JS logo

Developed by Brendan Eich and originally known as LiveScript, the programming language JavaScript was renamed in 1995 and is now a trademark of Oracle.

JavaScript is an interpreted client-side scripting language that allows a developer to insert code into their web page. JavaScript is commonly placed into an HTML (hypertext markup language) or ASP (Active Server Pages) file and runs directly from the web page and today is the most popular programming language. JavaScript can perform more advanced tasks, such as printing the time and date, creating a calendar, or other tasks that are impossible in HTML.

What is required to run JavaScript?

JavaScript only requires an Internet browser with JavaScript enabled, which all browsers have by default.

Is JavaScript safe?

Because JavaScript is downloaded from an unknown origin and executed on your computer, it could be malicious. To address this issue, Sun implemented tight security features from the earlier stages of development. These features include:

  • When the browser runs the JavaScript, it's isolated to the browser process. Browsers, like Chrome and Edge, sandbox JavaScript as an additional security measure.
  • JavaScript cannot read from or write to the hard drive or another storage device connected to the computer.

However, even with the above safety measures, anything connected to the Internet is never 100% safe, and a computer can be compromised using JavaScript. To help prevent possible security breaches, JavaScript can be disabled. However, most sites today require JavaScript to be fully operational. Alternatively, you can always ensure you're running the latest version of your browser to help keep it safe. There are also browser add-ons that can be installed to help control JavaScript or its features on websites.

Are Java and JavaScript the same thing?

No. Java and JavaScript are different computer programming languages with a few similarities. To learn one of the languages and want to develop features for the Internet and websites, learn JavaScript. To develop applications (e.g., a game that runs on a computer or smartphone without a browser), learn Java. See our Java definition for further information about Java.

Hello, World! in JavaScript

<SCRIPT LANGUAGE="JavaScript">
<! -- Hide from old browsers
document.write('Hello World!');
// Stop hide -->
</SCRIPT>
Tip

With HTML5, you no longer need to specify the language attribute.

Live example of JavaScript

Below is an example of a JavaScript implemented into this page that prints the current time and date. Like all JavaScript files, the user's Internet browser must be capable of viewing JavaScript, and the execution of JavaScript must be enabled. If JavaScript is not enabled, the time and date are not visible.

Tip

See the JavaScript time and date source code to use these JavaScript features in a web page.

Although JavaScript files are often embedded into the HTML file, users can save their JavaScript code in an external file. This file often ends with a .js file extension.

What is a JavaScript error?

A JavaScript error is any error encountered when running JavaScript. These errors are reported so the developer knows that an error exists and point them to where it exists in the code. As a user, you cannot fix the error and should report it to the developer behind the website where the error is being encountered.

List of JavaScript example scripts

Below are JavaScript examples we've collected and created that help demonstrate different abilities of JavaScript and include them in your website.

Bookmarklet, CamelCase, Grasshopper, Java, JavaScriptCore, JavaScript Hijacking, jQuery, JScript, LiveScript, Programming terms, Server-side scripting, Userscript, VBScript, Web design terms