JavaScript adds an interactive element to websites.
Known as the scripting language for Web pages.[^1]
Do not confuse JavaScript with the Java programming language — JavaScript is not “Interpreted Java”. Both “Java” and “JavaScript” are trademarks or registered trademarks of Oracle in the U.S. and other countries. However, the two programming languages have very different syntax, semantics, and use. [^1]
JavaScript documentation of core language features:
We can distinguish 3 major parts of what we usually refer to as “JavaScript”.
- The language itself. This is fairly standard among the various environments, both in the various browsers and in the various server-side environments.
- The DOM API - how the language can interact with the various parts of a web page while in the browser. While in this respect the various browsers are getting closer to each other they still differ. Several libraries, most prominently JQuery, is trying to provide a unified API.
- The server API (or just API) provided by Node.js or one of the other server-side systems. [^2]
When applying JavaScript to HTML, it preferred to include an external file within the HTML similar to CSS. Another option is to embed JavaScript directly in a line in the HTML.
A simple example of embedded JavaScript is the alert function. This creates a pop-up in the browser with the text.
- examples/js/alert.html
<script language="javascript"> alert("Hello World"); </script>[^2]
<script>code</script>
- examples/js/alert.html
<script language="javascript"> alert("Hello World"); </script>[^2]
app.js file that should be linked in the <head> section with a <script> tag using the app.js attribute.<script src="app.js></script>declaration: let myAge = '38'declaration: myAge = '39'const myName = 'Justin'const usersName = prompt("What is your name?");if (usersName =="Jay"){
alert("Hiya Teach");
}else {alert("Glad to have you here");}const usersName = prompt("What is your name?");if (usersName =="Jay"){alert("Hiya Teach");}else if (unserName == "Joe"){alert("Yo Joe!!!");}else {alert("Glad to have you here!);}“JavaScript” developer.mozilla.org
“Introduction to JavaScript - basic output” code-maven.com
“JavaScript input with prompt and confirm” code-maven.com
“JavaScript Variables” w3schools.com