Core JavaScript Built-in Objects
JavaScript provides a rich set of built-in objects immediately available in the runtime environment. These native types handle text processing, mathematical computations, numeric conversions, and temporal data without requiring external dependencies.
String Manipulation
String primitives automatically wrap with object methods for text processing. Modern JavaScript supports bracket notation for character access and template literals for concatenation.
const phrase = "JavaScript Programming";
// Character access patterns
console.log(phrase[0]); // First character
console.log(phrase.charAt(phrase.length - 1)); // Last character
// Concatenation strategies
const greeting = "Hello";
const subject = "World";
const message = `${greeting} ${subject}`; // Template literal interpolation
const hyphenated = ["data", "structure", "algorithm"].join("-");
// Extraction and repetition
const snippet = phrase.substring(11, 15); // "Prog"
const repeated = "*".repeat(10); // "**********"
const sliced = phrase.slice(-11); // Last 11 characters
// Dynamic execution context
const executable = "const dynamicValue = 42";
eval(executable);
console.log(dynamicValue); // Outputs 42
Numeric Operations and Validation
The Number object acts as both a wrapper for primitives and a utility namespace containing mathematical limits and parsing functions.
// Boundary constants
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991
console.log(Number.MIN_VALUE); // Smallest positive number
console.log(Number.POSITIVE_INFINITY); // Infinity representation
// Type conversion utilities
const floatResult = Number.parseFloat("3.14159 meters");
const intResult = Number.parseInt("1010", 2); // Binary to decimal: 10
// Validation and classification
const quotient = 0 / 0;
console.log(Number.isNaN(quotient)); // true
console.log(Number.isFinite(1e308)); // true
console.log(Number.isInteger(5.0)); // true (integral value)
console.log(Number.isSafeInteger(Math.pow(2, 53))); // false (beyond safe range)
Mathematical Computations
The Math namespace provides static methods to advanced arithmetic, trigonometry, and pseudo-random number generation.
// Rounding methodologies
Math.round(4.5); // Standard rounding: 5
Math.floor(4.9); // Downward rounding: 4
Math.ceil(4.1); // Upward rounding: 5
Math.trunc(4.9); // Remove decimal: 4
// Statistical and power functions
Math.max(10, 50, 5, 25); // 50
Math.min(...[5, 2, 8, 1]); // 1 (with spread operator)
Math.sqrt(256); // 16
Math.cbrt(27); // 3 (cube root)
// Randomization utilities
function getRandomInt(minimum, maximum) {
const range = maximum - minimum + 1;
return Math.floor(Math.random() * range) + minimum;
}
const randomAngle = Math.random() * Math.PI * 2; // 0 to 2π radians
Date and Time Management
Date objects represent specific instants as milliseconds elapsed since the Unix Epoch (January 1, 1970 UTC).
// Instantiation patterns
const now = new Date();
const epoch = new Date(0); // Epoch start
const specific = new Date("2024-06-15T09:30:00");
const constructed = new Date(2024, 5, 15, 9, 30); // Month index starts at 0
// Component retrieval
const appointment = new Date(2024, 11, 25, 14, 0);
console.log(appointment.getFullYear()); // 2024
console.log(appointment.getMonth()); // 11 (December)
console.log(appointment.getDate()); // 25 (Day of month)
console.log(appointment.getDay()); // 3 (Wednesday)
// Temporal comparisons
const deadline = new Date(2024, 11, 31, 23, 59);
console.log(now < deadline); // Boolean chronological comparison
// Custom formatting via prototype extension
Date.prototype.format = function(pattern) {
const tokens = {
yyyy: this.getFullYear(),
MM: String(this.getMonth() + 1).padStart(2, '0'),
dd: String(this.getDate()).padStart(2, '0'),
HH: String(this.getHours()).padStart(2, '0'),
mm: String(this.getMinutes()).padStart(2, '0'),
ss: String(this.getSeconds()).padStart(2, '0')
};
return pattern.replace(/yyyy|MM|dd|HH|mm|ss/g, match => tokens[match]);
};
console.log(appointment.format("yyyy-MM-dd HH:mm:ss"));