Skip to content
JavaScript Fundamentals

JavaScript Basics

Beginner Lesson 2 of 10

Master the building blocks of JavaScript programming.

// let - can be reassigned
let count = 0;
count = 1;
// const - cannot be reassigned
const PI = 3.14159;
// PI = 3; // Error!
// var - old way (avoid in modern JS)
var oldStyle = "legacy";
// Primitive types
let str = "Hello"; // String
let num = 42; // Number
let bool = true; // Boolean
let undef = undefined; // Undefined
let nothing = null; // Null
let sym = Symbol("id"); // Symbol
let big = 9007199254740991n; // BigInt
// Reference types
let arr = [1, 2, 3]; // Array
let obj = { name: "Alice", age: 25 }; // Object
let func = function() {}; // Function
// Arithmetic
let sum = 5 + 3; // 8
let diff = 5 - 3; // 2
let prod = 5 * 3; // 15
let quot = 5 / 3; // 1.666...
let rem = 5 % 3; // 2
let pow = 5 ** 3; // 125
// Comparison
5 == "5" // true (loose equality)
5 === "5" // false (strict equality - preferred!)
5 !== "5" // true
// Logical
true && false // false
true || false // true
!true // false
let name = "Alice";
let greeting = `Hello, ${name}!`; // Template literal
// String methods
"hello".toUpperCase(); // "HELLO"
" hello ".trim(); // "hello"
"hello".includes("ell"); // true
"hello".split(""); // ["h","e","l","l","o"]

Continue learning JavaScript with arrays, objects, and functions!