Last updated
JavaScript Where To
Definition: In a real website, JavaScript lives inside <script> tags or in a separate .js file linked to the page. Here, the editor runs it for you so you can focus on the language.
Example 1 — inside a web page
This is how JavaScript appears in an HTML file (so you recognise it later):
<script>
console.log("Hello from a web page");
</script>
Example 2 — ways to show output
console.log(...)— prints to the console (used here)alert(...)— a pop-up box in a real browser- Writing into the page itself (you will learn this with the DOM)
console.log("A simple message");
console.log("You can log numbers too:", 42);
Example 3 — logging several values
console.log accepts many values separated by commas and prints them on one line:
let name = "Sam";
let age = 20;
console.log("Name:", name, "Age:", age);
💡 Tip: console.log is your best friend for checking what your code is doing.
Try it Yourself
Output
Ad · responsive