# Strings, numbers and dates

*JavaScript Developer Study Guide · Variables, Types, and Collections · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/variables-types-and-collections/strings-numbers-and-dates*

The string, number and Date behaviors that decide 'what is logged' questions: immutable strings and slice vs substring, floating-point error and toFixed returning a string, parseInt vs Number, safe integers and BigInt, currency formatting with Intl.NumberFormat, zero-based months, UTC date-only parsing and date arithmetic.

- Certification: Salesforce JavaScript Developer
- Exam section: Variables, Types, and Collections
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a business requirement, utilize strings, numbers, and dates effectively.

## What the exam expects

- Predict the result of string methods (`slice`, `substring`, `replace`, `padStart`, `split`/`join`, template literals) and remember that none of them changes the original string.
- Handle money and IDs: explain `0.1 + 0.2 !== 0.3`, know that `toFixed()` returns a string, and keep integers above `Number.MAX_SAFE_INTEGER` as strings or `BigInt`.
- Choose between `Number()`, unary `+`, `parseInt()` and `parseFloat()` for strings such as `'42px'`.
- Format currency for a locale with `Intl.NumberFormat` (or `toLocaleString` with the same options).
- Build and compare dates: zero-based months, local vs UTC parsing, overflow when setting components, and subtracting dates to get milliseconds.
- Key terms: **immutable** (a primitive value can never be changed in place); **IEEE 754 double** (the 64-bit binary format of every `number`); **safe integer** (an integer the format represents exactly, up to 2^53 − 1); **timestamp** (milliseconds since 1 January 1970 UTC, the value inside every `Date`); **locale** (language and region whose formatting rules apply).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| String methods | Return new strings; index assignment does not change a string | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) |
| `substring()` with a negative argument | Treated as 0 | [String.prototype.substring()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) |
| `replace()` with a string pattern | First occurrence only | [String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) |
| `toFixed()` | Returns a string, rounded and zero-padded | [Number.prototype.toFixed()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) |
| `Number('')` | 0; `Number('42px')` is `NaN` | [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) |
| `parseInt` radix | Not always 10 when omitted; pass it | [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) |
| `Number.MAX_SAFE_INTEGER` | 9007199254740991 (2^53 − 1) | [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) |
| `BigInt` with `number` | Cannot be mixed in arithmetic | [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) |
| Currency format | `style: 'currency'` plus a `currency` code | [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) |
| Month index | Zero-based: 0 = January, 11 = December | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| Date-only ISO string | Parsed as UTC; date-time without offset is local | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| `dateB - dateA` | Difference in milliseconds | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |

## Check yourself

- Why does `0.1 + 0.2 === 0.3` return `false`?
- When should a large numeric ID be kept as a string or `BigInt`?
- Why does `new Date('2025-07-04').getDate()` return 3 in California?
- Which call formats 1234.5 as `$1,234.50`?
- What does `'cloud'.toUpperCase()` do to the original string?

## Sources

- [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
- [String.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
- [String.prototype.substring()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
- [String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
- [String.prototype.padStart()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
- [Template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)
- [Number.prototype.toFixed()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
- [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
- [parseFloat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
- [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
- [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
- [Number.prototype.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
- [Date.prototype.setMonth()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
- [Addition (+)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition)
- [Primitive](https://developer.mozilla.org/en-US/docs/Glossary/Primitive)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 13 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
