JavaScript Fundamentals · Introduction · Lesson 2 of 48
Setting Up and Running Code
Concept
Setting Up and Running Code
You can run JavaScript directly in a browser console, inside a script tag, or in an editor like the one below. A program executes from the top of the file, line by line.
Most real websites keep JavaScript in a separate .js file and link it with a script tag, rather than writing it inline in the HTML.
By the end of this lesson
- Explain the core idea behind Setting Up and Running Code.
- Predict output before running a change.
- Test one realistic and one unusual input.
- Use the result to make the next decision.
How to study this page
- 1. Read one concept.
- 2. Change the example.
- 3. Run, compare, and explain.
- 4. Complete the challenge below.
Syntax
<script src="script.js"></script>Linking an external script
<script src="script.js"></script>Note: Placing the script tag right before the closing </body> tag ensures the page's HTML loads first.
Self-check before continuing
Without looking at the example, describe what changes when you modify one input in Setting Up and Running Code. Then reopen the editor and prove your explanation with a small test.
You are ready to continue when you can predict, test, and explain the result.
Your turn
Change the message variable to say something about yourself, then run the code.
Loading editor…
Console