LESSON 2
How JavaScript Works
Learning objective: Learn where JavaScript runs and how to add it to a page.
Understand
JavaScript runs inside the browser's engine.
You add JavaScript with a <script> tag, ideally just before </body> so the HTML loads first. The browser reads your script top to bottom and runs each statement. Use the developer console to see output and errors.
Analogy: The browser is like a reader following your recipe line by line.
See It in Action
Linking an external script and logging:
<script src="app.js"></script>
<!-- in app.js: -->
console.log("Ready!");How it works: The
<script src> loads your file, and console.log prints a message to the browser console for debugging.Try It Yourself
- Create an
app.jsfile and link it. - Log a message with
console.log. - Open dev tools and read the console.
Quick Quiz
Where is it best to place a script tag?
Challenge
Link an external script that logs a message to the console.
Success condition: Your console shows the message from an external script file.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →