JavaScript
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>
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.
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.
- Celsius into Fahrenheit.
- Time and date.
- Make people stay.
- JavaScript bookmark.
- Letter by letter scroll.
- Date countdown.
- Make a new small window of another web page.
- Button to refresh your web page.
- Send viewers back to the page they came from.
- Change the background color depending on the time of day.
- Random color every 5 seconds.
- Random color that can be stopped.
- Flashing colors when opening a web page.
- Allow visitors to see the history of visiting your web page.
- Random quote.
- Message displayed by time of day.
- Message on status bar.
- Random images and links.
- Creating a password on your web page.
- Disable mouse right-click.
- Pop-up message box.
Bookmarklet, CamelCase, Grasshopper, Java, JavaScriptCore, JavaScript Hijacking, jQuery, JScript, LiveScript, Programming terms, Server-side scripting, Userscript, VBScript, Web design terms