Skip to content
JavaScript Fundamentals

JavaScript Data Types

Beginner Lesson 3 of 10

JavaScript has dynamic typing - variables can hold any type of value.

const single = 'Hello';
const double = "World";
const template = `Hello, ${name}!`;
// String methods
"hello".toUpperCase(); // "HELLO"
"hello".length; // 5
"hello".charAt(0); // "h"
"hello".includes("ell"); // true
const integer = 42;
const float = 3.14;
const negative = -10;
const infinity = Infinity;
const notANumber = NaN;
// Number methods
Number.isInteger(42); // true
Number.parseFloat("3.14"); // 3.14
(3.14159).toFixed(2); // "3.14"
const isTrue = true;
const isFalse = false;
// Truthy values: true, 1, "string", [], {}
// Falsy values: false, 0, "", null, undefined, NaN
const arr = [1, 2, 3, 4, 5];
arr.push(6); // Add to end
arr.pop(); // Remove from end
arr.map(x => x * 2); // [2, 4, 6, 8, 10]
arr.filter(x => x > 2); // [3, 4, 5]
arr.reduce((a, b) => a + b, 0); // 15
const person = {
name: "Alice",
age: 25,
greet() {
return `Hi, I'm ${this.name}`;
}
};
person.name; // "Alice"
person["age"]; // 25
Object.keys(person); // ["name", "age", "greet"]
typeof "hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" (quirk!)
typeof [] // "object"
typeof {} // "object"
Array.isArray([]) // true

Continue to Functions →