JavaScript
JavaScript (JS) is a program which can be executed in browser, so you can use it to change web contents, or control your web logic.
Where to insert JS codes
In HTML
You can put JS codes between tags in your HTML file. Example:
The answer is: <span id="demo"></span>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
2
3
4
5
Page result:
Here we use JS code to grab the element with ID="demo" and change its content to 11.
In external file
If you write codes at online platforms such as jsbin or jsFiddle, then put JS codes inside JavaScript part. The platform will execute the JS codes for you. If you write codes in local files, then use the following syntax to insert and execute your JS codes. (Here we assume your JS file is called myscripts.js)
<script src="myscripts.js"></script>
Hello, JS
Let's try these simple commands.
Example 1
window.alert("This is the alert message.");
Example 2
console.log("This is the console message.");
Example 3
Exercise
In this course, we only introduce JS a little bit, but you are encouraged to learn it more by yourself. Try to learn it from SoloLearn and w3schools - JavaScript Tutorial.