JavaScript Introduction
JavaScript is the programming language of the web. It can update and change both HTML and CSS, and it can calculate, manipulate, and validate data.
What Can JavaScript Do?
| Capability | Example |
|---|---|
| Change HTML Content | document.getElementById("demo").innerHTML = "Hello" |
| Change HTML Styles | element.style.fontSize = "35px" |
| Change Attributes | element.src = "new-image.png" |
| Hide Elements | element.style.display = "none" |
| Show Elements | element.style.display = "block" |
Change HTML Content
The most common use of JavaScript is to dynamically modify HTML content using innerHTML.
Example
// Change the text of an element
document.getElementById("demo").innerHTML = "Hello JavaScript!";
console.log("Element updated!");Change HTML Styles (CSS)
Example
// Change font size dynamically
document.getElementById("demo").style.fontSize = "35px";
console.log("Style changed!");A Bit of History
JavaScript was invented by Brendan Eich in 1995. It became an ECMA standard in 1997. ECMA-262 is the official standard name. ECMAScript is the official name of the language.
📝 Note: JavaScript and Java are completely different languages, both in concept and design.
Exercise:
What was JavaScript originally created for?