Data Types Exercise 3

BigInt is a numeric data type that can represent integers with arbitrary precision. It is used for very large integers that exceed the safe integer limit of the Number type. You can create a BigInt by appending n to an integer literal or using the BigInt() function.

You can create a BigInt by appending n to an integer: let big = 9007199254740991n;. You can also use the BigInt() function: let big = BigInt(9007199254740991);.

An array is a special variable that can hold multiple values at once. Arrays are ordered, and each element is accessed by its numeric index starting from 0. Example: let fruits = ["apple", "banana", "cherry"];

You declare an array using square brackets: let arr = [1, 2, 3];. You can also use the Array constructor: let arr = new Array(1, 2, 3);.

Primitive data types (such as Number, String, Boolean, null, undefined, Symbol, BigInt) are immutable and stored by value. Non-primitive types (such as objects and arrays) are stored by reference, meaning variables hold a reference to the memory location of the value.

typeof null returns "object". This is a well-known bug in JavaScript kept for backward compatibility. Despite the result, null is not an object — it is a primitive value.

NaN stands for "Not a Number". It is a special numeric value that results from an invalid or undefined mathematical operation, such as dividing zero by zero or parsing a non-numeric string as a number.

Use the isNaN() function or the more reliable Number.isNaN() method. Example: Number.isNaN(NaN) returns true, while Number.isNaN("hello") returns false (unlike the global isNaN()).

Infinity is a special numeric value representing mathematical infinity. It results from operations like dividing a positive number by zero: 1 / 0 === Infinity. There is also -Infinity for negative infinity.

typeof returns a string indicating the primitive type of a value (e.g., "string", "number"). instanceof checks whether an object was created by a specific constructor (e.g., [] instanceof Array returns true). Use typeof for primitives and instanceof for objects.