Introduction to JavaScript
JavaScript is a programming language that runs in the browser. Unlike HTML and CSS, which describe structure and appearance, JavaScript describes behavior — what should happen and when.
Adding JavaScript to a page
JavaScript is usually added with a <script> tag, either linking to a separate file or written directly on the page:
</> linking a script file
<body> ... <script src="script.js"></script> </body>
Placing the <script> tag near the end of <body> is common practice, so the page's HTML loads first before the script runs.
console.log
console.log() prints a value out, which is useful for checking what your code is doing as you write it. Every example in this course shows its console output below the code — try changing the message:
Note: in a real browser, console output normally appears in the developer tools panel (usually opened with F12). This course shows it directly on the page instead, so you don't have to open anything extra.