topskill.dev
CoursesTracks
All courses/Introduction to JavaScriptNumber and BigInt Boundaries
Objects and Built-ins
7 / 17
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Missing values and deliberate emptiness○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Comparisons and strict equality○Truthiness and combined conditions○Function inputs and results○Conditionals○Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Stop a Ticket Scan○Challenge: Number Guess Referee○Rainfall Routing Walkthrough○Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Ticket Pricing Walkthrough○Shipping Labels with Defaults○Seat Ledger Closure Walkthrough○Private Budget Ledger✦Module Quiz
○Arrays○Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Charging Rack Restock Report○Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Object copies and optional properties○Map and Set Collections○Playlist Lookup●Number and BigInt Boundaries○Ticket Ledger○JSON○Throwing and catching errors○Math and Date○Date Basics○Supply Bin Audit○Volunteer Shift Audit○Workshop Attendance Feed○Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Build a Reminder with Template Literals○Format Pantry Pickup Messages○Validate a Time Slot with Regex○Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Extend the inventory report○Handle an Error-First Callback○Report Seat Reservation Results○Summarize Completed Bike Rides○Summarize Delivered Parcels✦Module Quiz
○A notebook object○OOP Introduction○Independent workshop passes○Classes○An inherited notice○Inheritance○A private seat counter○Encapsulation○Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Callback Timing○Asynchronous JavaScript○Promise Rehearsal○Promises and Async Await○Offline API Coordination○Async API Simulation○Partial Results Bulletin○Project: Resilient Awards Feed○Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Number and BigInt Boundaries

Numeric text and a number are different values. Number("42.5") converts text so you can calculate with it. If conversion fails, the result is NaN, short for "not a number"; use Number.isNaN(value) to check for that result.

javascript
const parsedScore = Number("42.5");
const invalidScore = Number("north");
const largeTicket = 9007199254740993n;
console.log(parsedScore);
console.log(Number.isNaN(invalidScore));
console.log(largeTicket > 9007199254740992n);

Run the example. The score becomes 42.5, the failed conversion is detected, and the two large IDs remain distinct.

Conversion is not complete input validation: Number("") and Number(" ") both produce zero. Reject blank input separately when a blank field should mean "missing". A converted value can also be infinite; Number.isFinite(value) checks that it is neither infinite nor NaN.

Keep large integers exact

Number uses floating-point storage. It cannot represent every decimal fraction exactly, and beyond Number.MAX_SAFE_INTEGER (9007199254740991), it cannot reliably distinguish every adjacent integer. BigInt stores whole integers exactly. The n suffix creates a BigInt literal; BigInt("9007199254740993") converts an integer string without first rounding it as a Number.

Do not write a large ID as a Number and then convert it to BigInt: any lost precision is already gone. Converting a large BigInt to Number can lose precision too. In the next exercise you will convert only a small ticket count, never the identifier.

The safe-integer limit also applies to negative values: use the range from Number.MIN_SAFE_INTEGER through Number.MAX_SAFE_INTEGER when every integer must remain distinguishable.

BigInt does not hold fractional values. Arithmetic operands must have matching numeric types: 3n * 2n works, but 3n * 2 throws. Convert deliberately when the value is safely within the other type's range.

Learn more

MDN's Number and BigInt references explain conversion and precision limits.