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 programming language that runs in web browsers and on servers. Originally created in just 10 days by Brendan Eich in 1995, it has grown to 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);

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");

Try It Yourself

Now it's your turn! Modify the code below to:

  1. Print your name
  2. Print your favorite number
  3. Calculate and print the result of 10 + 20
  4. 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!

Introduction to JavaScript | LearningJavaScript.org