<htmlstart/>

Introduction to JavaScript

What JavaScript is and why it is the language of the web.

What is JavaScript?

JavaScript is the programming language of the web. It runs inside every browser and lets you make pages interactive — respond to clicks, update content, fetch data, animate elements, and much more.

TechnologyRole
HTMLStructure — the skeleton
CSSDesign — the appearance
JavaScriptBehaviour — the interactivity

Your First JavaScript

<button onclick="greet()">Say hello</button>

<script>
function greet() {
  alert("Hello, World!");
}
</script>

Where JavaScript Runs

  • Browser — built into Chrome, Firefox, Safari, Edge
  • Server — Node.js runs JS outside the browser
  • Mobile apps — React Native, Capacitor
  • Desktop apps — Electron (VS Code is built with it)

Adding JS to a Page

<!-- Inline (small scripts) -->
<script>
  console.log("Hello from inline script");
</script>

<!-- External file (recommended) -->
<script src="app.js" defer></script>
Use defer on external scripts — the browser downloads the file in the background and runs it after the HTML is fully parsed. No blocking, no ordering issues.
🧩

Test Yourself

4 questions
Q1.What role does JavaScript play in web development?
Q2.Where does JavaScript code run by default?
Q3.Which attribute makes an external script non-blocking?
Q4.Which HTML tag is used to add JavaScript to a page?