Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Data types are categories that tell JavaScript what kind of data you're working with. Just like organizing items in drawers - numbers go in one drawer, text in another!
Text data
Numbers
true/false
Not set yet
Intentionally empty
Unique identifier
Very large numbers
Strings are text wrapped in quotes. You can use single quotes, double quotes, or backticks!
const name = 'Alice'; // Single quotes const city = "New York"; // Double quotes const message = `Hello!`; // Backticks console.log(name); // Alice console.log(typeof name); // string
Different ways to create strings
JavaScript has one number type for all numbers - whole numbers, decimals, negative numbers, all use the same type!
const age = 25; // Whole number const price = 19.99; // Decimal const temperature = -5; // Negative console.log(typeof age); // number console.log(typeof price); // number
Working with numbers
Booleans have only two possible values: true or false. Like a light switch - on or off!
const isLoggedIn = true;
const hasPermission = false;
const isAdult = true;
console.log(typeof isLoggedIn); // boolean
// Used in conditions
if (isLoggedIn) {
console.log('Welcome!');
}True/false values in action
Variables that are declared but not assigned a value are automatically undefined
let name; console.log(name); // undefined let age; console.log(typeof age); // undefined // Not set yet!
You set a variable to null on purpose to say "this is empty by design"
let user = null; console.log(user); // null console.log(typeof user); // object // (this is a JS quirk!) // Cleared on purpose!
Understanding the difference
Use typeof to check what type a value is!
console.log(typeof 'Hello'); // string console.log(typeof 42); // number console.log(typeof true); // boolean console.log(typeof undefined); // undefined console.log(typeof null); // object (quirk!) console.log(typeof Symbol()); // symbol console.log(typeof 123n); // bigint
Checking types before using values
typeof to check typesundefined ≠ null