FREE COURSE | BEGINNER
JavaScript
Learn the fundamentals of JavaScript and build interactive web experiences.
Learning objectives
- Write and explain basic JavaScript statements and expressions.
- Apply variables, operators, conditions, loops and functions.
- Respond to browser events and test code independently.
01. Introduction to JavaScript
JavaScript is a programming language used to add behavior to webpages. HTML describes structure, CSS controls presentation, and JavaScript responds to actions and changes content. JavaScript also runs outside browsers in environments such as Node.js. JavaScript and Java are different languages.
Editable source code
Output
Hello, LOOPNODELAB!
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Change the message and predict the output.
02. JavaScript Syntax
Statements perform actions. JavaScript is case-sensitive: score and Score are different names. Strings use quotes, and // starts a single-line comment. Semicolons are optional in many situations, but we use them consistently.
Editable source code
Output
Learning JavaScript 5
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Change the numbers and explain the difference between quoted text and arithmetic.
03. Variables and Data Types
Use let for a binding that may be reassigned and const for a binding that will not be reassigned. Common primitive types include string, number, boolean, undefined, null, bigint and symbol. Objects group related data. A const object can still have its properties changed.
Editable source code
Output
Learner 15 true number
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Change the starting score. What happens if you try to reassign name?
04. Operators
Arithmetic operators include +, -, *, / and %. Use === for strict equality and !== for strict inequality. Comparisons produce booleans. Logical operators &&, || and ! combine or negate conditions. The + operator can also concatenate strings.
Editable source code
Output
13 1 true
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Predict the remainder when a is 12 and b is 5.
05. Conditional Statements
An if statement executes a block when its condition is truthy. An else if tests another condition, and else handles the remaining case. Order matters because only the first matching branch runs.
Editable source code
Output
Passed
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Test scores of 90, 75 and 74. Explain each result.
06. Loops
A for loop combines initialization, a condition and an update. A while loop repeats while its condition is truthy. Ensure the condition eventually becomes false to avoid an infinite loop.
Editable source code
Output
1 2 3 2 1
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Modify the for loop to print even numbers from 2 to 10.
07. Functions
A function groups reusable instructions. Parameters are names in the declaration; arguments are values supplied when calling it. return sends a value back to the caller. Without an explicit return value, a normal function returns undefined.
Editable source code
Output
75
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Call total with different prices and quantities.
08. DOM Manipulation and Events
The Document Object Model (DOM) represents webpage elements as objects. querySelector selects the first matching element, textContent changes its text, and addEventListener registers a function to respond to an event. The example below runs in the isolated preview provided in this lesson.
Editable source code
Output
Click the preview button: the message changes to You clicked!
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Run the example, click the preview button, then change the message.
09. Interactive JavaScript Playground
Combine variables, conditions, loops and functions to solve a problem. Predict the result before running the code. Compare the actual output with your prediction and debug any differences.
Editable source code
Output
15
Initial output is an example. Run Code executes your edited JavaScript.
Try it yourself
Change the limit to 10. Then write a function that counts even numbers.
10. Knowledge Check
Test your understanding of JavaScript fundamentals.