G
Gouranga Das Samrat
Guest
JavaScriptβs built-in functions are your Swiss Army knife for daily coding tasks and technical interviews. Beyond the basics, here are some powerful functions with real-world applications.








































These functions represent the core toolkit Iβve relied on throughout my career for real-world JavaScript challenges, interviews, and projects. While no one needs to memorize them all in the age of AI, having this mental index helps tremendously when youβre stuck designing complex logic during coding challenges or debugging sessions. Keep this reference handyβββnot as a study guide, but as a practical map to navigate JavaScriptβs built-in capabilities efficiently when tackling tough problems.
When in doubt: Combine simple functions instead of writing complex code.

Continue reading...
Math
Code:
// Math.random()
// Use: Generate random numbers
// Case: OTP generation, random sampling
Math.random();

Code:
// Math.floor() vs Math.ceil()
// Use: Precise number handling
// Case: Pagination, financial calculations
Math.floor(4.7); // 4
Math.ceil(4.2); // 5

Code:
// Math.max()/Math.min()
// Use: Find extremes in datasets
// Case: Data analysis, validation
Math.max(1, 2, 3); // 3
Math.min(1, 2, 3); // 1

Code:
// Math.abs(x)
// Use: Absolute value
// Case: Distance calculations, input validation
Math.abs(-42); // 42

Code:
// Math.pow(base, exponent)
// Use: Exponentiation
// Case: Compound interest, animation curves
Math.pow(2, 3); // 8

Advanced String Magic
Code:
// str.includes()
// Use: Substring detection
// Case: Search features, content filtering
"hello world".includes("world"); // true

Code:
// str.split()
// Use: String β Array conversion
// Case: CSV parsing, text processing
"a,b,c".split(","); // ['a', 'b', 'c']

Code:
// str.trim()
// Use: Remove whitespace
// Case: Form input sanitization
" hello ".trim(); // 'hello'

Code:
// str.substring(start, end)
// Use: Extract substring between indices
// Case: Truncating text, parsing IDs
"abcdef".substring(1, 4); // 'bcd'

Code:
// str.charAt(index)
// Use: Safe character access (vs str[index] in older JS)
// Case: Password validators, string analysis
"abc".charAt(1); // 'b'

Code:
// str.padStart(length, padding)
// Use: Format strings to fixed length
// Case: Display IDs, financial formatting
"5".padStart(3, "0"); // '005'

Code:
// str.match(regex)
// Use: Extract patterns with regex
// Case: Data scraping, validation
"apple123".match(/\d+/); // ['123']

Code:
// str.repeat(count)
// Use: Create repeated strings
// Case: Loading animations, text formatting
"abc".repeat(3); // 'abcabcabc'

Code:
// str.endsWith(searchString)
// Use: Suffix verification
// Case: File type validation
"file.txt".endsWith(".txt"); // true

Advanced Array Techniques
Code:
// arr.find()
// Use: Find first match
// Case: User lookup, inventory search
[1, 2, 3].find((x) => x > 1); // 2

Code:
// arr.some()/arr.every()
// Use: Conditional checks
// Case: Permissions, validation
[1, 2, 3].some((x) => x > 2); // true
[1, 2, 3].every((x) => x > 0); // true

Code:
// arr.reduce()
// Use: Accumulate values
// Case: Shopping carts, data aggregation
[1, 2, 3].reduce((a, b) => a + b, 0); // 6

Code:
// Array.from()
// Use: Convert array-likes to arrays
// Case: DOM manipulation, arguments handling
Array.from("abc"); // ['a', 'b', 'c']

Code:
// arr.splice(start, deleteCount, ...items)
// Use: Insert/remove elements at any position
// Case: Dynamic lists, reordering
let arr = [1, 2, 3];
arr.splice(1, 1, 4); // [1, 4, 3]

Code:
// arr.slice(start, end)
// Use: Create shallow copies of array segments
// Case: Pagination, undo/redo features
[1, 2, 3, 4].slice(1, 3); // [2, 3]

Code:
// arr.flat(depth)
// Use: Flatten nested arrays
// Case: API response normalization
[1, [2, [3]]].flat(2); // [1, 2, 3]

Code:
// arr.findIndex(callback)
// Use: Find position of first matching element
// Case: Bulk operations, data indexing
[1, 2, 3].findIndex((x) => x === 2); // 1

Code:
// arr.join(separator)
// Use: Convert array β string with custom separator
// Case: CSV generation, URL parameters
[1, 2, 3].join("-"); // '1-2-3'

Code:
// arr.reverse()
// Use: Reverse element order
// Case: UI rendering (newest first), palindrome checks
[1, 2, 3].reverse(); // [3, 2, 1]

Code:
// arr.fill(value, start, end)
// Use: Initialize arrays with default values
// Case: Matrix creation, reset operations
Array(3).fill(0); // [0, 0, 0]

Code:
// arr.flatMap(callback)
// Use: Map + flatten in single operation
// Case: Data normalization, tag processing
[1, 2, 3].flatMap((x) => [x, x * 2]); // [1, 2, 2, 4, 3, 6]

Date Manipulation
Code:
// Date.parse()
// Use: Convert string β timestamp
// Case: Time calculations, countdowns
Date.parse("2025-07-03");

Code:
// new Date() Constructor
// Use: Create date objects from various inputs
// Case: User input handling, timestamp conversion
new Date("2025-07-03");

Code:
// date.getFullYear()/date.getMonth()/date.getDate()
// Use: Extract date components
// Case: Age calculation, date formatting
const d = new Date();
d.getFullYear();
d.getMonth();
d.getDate();

Code:
// date.setFullYear()/date.setMonth()
// Use: Modify date components
// Case: Subscription renewals, date arithmetic
d.setFullYear(2030);
d.setMonth(0); // January

Code:
// date.getDay()
// Use: Get weekday index (0=Sunday)
// Case: Scheduling, business day calculations
d.getDay();

Code:
// date.toISOString()
// Use: Convert to ISO 8601 format
// Case: API payloads, database storage
d.toISOString();

Code:
// date.toLocaleString(locale, options)
// Use: Fully localized date/time formatting
// Case: International applications
d.toLocaleString("en-US");

Code:
// date.getTimezoneOffset()
// Use: Get UTC offset in minutes
// Case: Timezone conversions
d.getTimezoneOffset();

Code:
// date.getUTCHours()
// Use: Get UTC hour (0β23)
// Case: Global scheduling systems
d.getUTCHours();

Code:
// date.setDate(day)
// Use: Set day of month (1β31)
// Case: Calendar navigation, due date calculation
d.setDate(15);

Code:
// date.toLocaleTimeString()
// Use: Culture-sensitive time formatting
// Case: Localized dashboards
d.toLocaleTimeString();

Utility Power Tools
Code:
// JSON.parse()/JSON.stringify()
// Use: Data serialization
const obj = JSON.parse('{"a":1}');
JSON.stringify(obj); // '{"a":1}'
Code:
// Object.keys()/Object.values()
// Use: Object introspection
// Case: Dynamic forms, configuration
Object.keys({ a: 1, b: 2 }); // ['a', 'b']
Object.values({ a: 1, b: 2 }); // [1, 2]
Code:
// Object.freeze(obj)
// Use: Make object immutable
// Case: Configuration objects, constants
const frozen = Object.freeze({ a: 1 });

Code:
// Number.toFixed(digits)
// Use: Fixed-point notation
// Case: Currency formatting, measurements
(3.14159).toFixed(2); // '3.14'

Code:
// Array.isArray(value)
// Use: Type checking for arrays
// Case: API response validation
Array.isArray([1, 2, 3]); // true

Conclusion
These functions represent the core toolkit Iβve relied on throughout my career for real-world JavaScript challenges, interviews, and projects. While no one needs to memorize them all in the age of AI, having this mental index helps tremendously when youβre stuck designing complex logic during coding challenges or debugging sessions. Keep this reference handyβββnot as a study guide, but as a practical map to navigate JavaScriptβs built-in capabilities efficiently when tackling tough problems.
When in doubt: Combine simple functions instead of writing complex code.
Code:
// Number.isInteger()
// Use: Validate numbers
// Case: Input validation, type checking
Number.isInteger(42); // true

Continue reading...