Week 1
JavaScript Basics

JavaScript First Steps

Learn the fundamentals of JavaScript programming!

Learning Objectives
  • Write your first JavaScript code
  • Understand how to include JavaScript in a web page
  • Learn about the JavaScript console

Explanation

Let's take our first steps with JavaScript! There are three main ways to add JavaScript to your web page: 1. Inline JavaScript: Adding JavaScript directly to HTML elements using attributes like onclick, onload, etc. 2. Internal JavaScript: Adding JavaScript inside <script> tags in your HTML document. 3. External JavaScript: Creating a separate .js file and linking to it from your HTML using <script src="script.js"></script>. When you're learning, it's very helpful to use the browser's console. You can open it by pressing F12 or right-clicking and selecting "Inspect" then going to the "Console" tab. This lets you write and test JavaScript code directly. One of the simplest ways to see that your JavaScript is working is to use console.log() to display messages in the console.
Code Example
// External JavaScript file (script.js)
console.log("Hello, JavaScript world!");

// In your HTML file
// <script src="script.js"></script>

// Or internal JavaScript
// <script>
//   console.log("Hello from inside the HTML!");
// </script>
Try It Yourself!

Try writing a simple console.log statement to display your name!

JavaScript Editor
Mini Quiz

Test your knowledge with these quick questions!

1. Where can you see the output of console.log() statements?

On the web page
In a popup message
In the browser console
In a text file

2. What's the best way to include JavaScript for a large website?

Inline JavaScript in each HTML element
Internal JavaScript in the <head> section
External JavaScript files
All methods are equally good
Your Progress
Lesson ProgressIn Progress
Est. time: 15-20 min
50 points
Module Progress
JavaScript Fundamentals2/10 completed

Complete all lessons to earn the Code Fundamentalist badge!

Rewards

Complete this lesson

Earn 50 points

Complete this module

Earn the Code Fundamentalist badge