TL;DR
Start learning JavaScript from scratch. This beginner tutorial covers why JS powers the web and how to write your first program.
Key concepts
- learn JavaScript
- JavaScript tutorial
- JavaScript basics
- JavaScript for beginners
Introduction to JavaScript
Welcome to your first lesson in JavaScript programming! JavaScript is the language that makes the web interactive and dynamic. Whether you're clicking a button, filling out a form, or watching animations, JavaScript is making it happen.
What You'll Learn
- What JavaScript is and why it's important
- How to write your first JavaScript program
- Basic syntax and console output
- How to run JavaScript code
What is JavaScript?
JavaScript is a high-level, interpreted (or just-in-time compiled) programming language that runs in web browsers and on servers. Brendan Eich built the first working prototype in about ten days in May 1995. It reached the public that September in a Netscape Navigator 2.0 beta, got the name "JavaScript" that December, and shipped for real in Navigator 2.0 in March 1996 — and it kept growing for years after. It has since become one of the most popular programming languages in the world.
Key Features
- Universal: Runs in every web browser without installation
- Versatile: Used for front-end, back-end, mobile apps, and more
- Beginner-friendly: Easy to start learning with immediate results
- Powerful: Can build everything from simple scripts to complex applications
Your First JavaScript Program
Let's start with the classic "Hello, World!" program:
console.log("Hello, World!");
When you run this code, you'll see "Hello, World!" appear in the output. The console.log() function is your best friend when learning JavaScript - it lets you see what's happening in your code.
Understanding Console Output
The console.log() function prints messages to the console. You can print text, numbers, and more:
// Printing text (strings)
console.log("Welcome to JavaScript!");
// Printing numbers
console.log(42);
console.log(3.14);
// Printing multiple values
console.log("The answer is:", 42);
// Printing calculations
console.log("5 + 3 =", 5 + 3);
Predict
Trace the last line by hand before running it. What does it log?
console.log("The answer is:", 42);
console.log("5 + 3 =", 5 + 3);Comments in JavaScript
Comments help you explain your code. JavaScript has two types of comments:
// This is a single-line comment
console.log("This will run"); // Comment at the end of a line
/*
This is a
multi-line comment
that spans several lines
*/
console.log("Comments are ignored by JavaScript");
Recall
Without scrolling up: which function do you call to print a value to the console in JavaScript?
Try It Yourself
Now it's your turn! Modify the code below to:
- Print your name
- Print your favorite number
- Calculate and print the result of 10 + 20
- Add a comment explaining what your code does
// Your code here
console.log("Hello, JavaScript!");
// Try adding more console.log statements
Key Takeaways
- JavaScript is the programming language of the web
console.log()is used to print output- Comments start with
//for single lines or/* */for multiple lines - JavaScript code runs line by line from top to bottom
Next Steps
In the next lesson, we'll learn about variables and data types - how to store and work with different kinds of information in JavaScript.
Pro Tip: The best way to learn JavaScript is by experimenting! Try changing the code examples above and see what happens. Don't be afraid to make mistakes - that's how you learn!
Two-tier handoff: this document is the complete reading surface. Continue learning for stateful practice, progress, and real sandbox execution.