JavaScript Introduction & Environment Setup
Understand what makes JavaScript the language of the web. Learn where JS runs, what it does, and how to include it in HTML.
What is JavaScript?
JavaScript (often abbreviated as JS) is a lightweight, interpreted, object-oriented language with first-class functions. It is best known as the scripting language for Web pages, allowing developers to create dynamically updating content, control multimedia, and animate images.
Where does JavaScript Run?
Historically, JS ran exclusively in the browser (client-side) using engines like Google's V8 or Mozilla's SpiderMonkey. Today, thanks to environments like Node.js, JavaScript can also run on the server-side.
Including JS in HTML
There are two primary ways to run JavaScript in a browser:
1. Internal Script
You can place JS directly inside an HTML file using the <script> tag.
<script>
console.log("Hello from inside HTML!");
</script>2. External Script
It is best practice to keep HTML and JS separate. You can link an external JS file.
<script src="app.js" defer></script>Note: The defer attribute ensures the script loads without blocking HTML parsing.