Skip to content

Commit e0175b0

Browse files
committed
Add ECMAScript 6 Number additions
1 parent c8c7336 commit e0175b0

1 file changed

Lines changed: 111 additions & 1 deletion

File tree

content/JavaScript/number.jsdoc

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ console.log(x.toLocaleString());
132132
Spec:
133133
http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.4.3
134134

135+
----
136+
MAX_SAFE_INTEGER : Number
137+
138+
The largest possible integer such that **MAX_SAFE_INTEGER**
139+
and **MAX_SAFE_INTEGER + 1** can both be represented exactly
140+
in JavaScript.
141+
142+
See also %%#MIN_SAFE_INTEGER|**MIN_SAFE_INTEGER**%% and
143+
%%#isSafeInteger|**Number.isSafeInteger()**%%.
144+
145+
<example>
146+
console.log(Number.MAX_SAFE_INTEGER);
147+
console.log(Number.MAX_SAFE_INTEGER + 1);
148+
console.log(Number.MAX_SAFE_INTEGER + 2);
149+
</example>
150+
151+
Spec:
152+
http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.3.2
153+
135154
----
136155
MAX_VALUE : Number
137156

@@ -145,6 +164,22 @@ console.log(Number.MAX_VALUE);
145164
Spec:
146165
http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.3.2
147166

167+
----
168+
MIN_SAFE_INTEGER : Number
169+
170+
The smallest possible integer such that **MIN_SAFE_INTEGER**
171+
and **MIN_SAFE_INTEGER - 1** can both be represented exactly
172+
in JavaScript.
173+
174+
See also %%#MAX_SAFE_INTEGER|**MAX_SAFE_INTEGER**%% and
175+
%%#isSafeInteger|**Number.isSafeInteger()**%%.
176+
177+
<example>
178+
console.log(Number.MIN_SAFE_INTEGER);
179+
console.log(Number.MIN_SAFE_INTEGER - 1);
180+
console.log(Number.MIN_SAFE_INTEGER - 2);
181+
</example>
182+
148183
----
149184
MIN_VALUE : Number
150185

@@ -163,7 +198,9 @@ NaN : Number
163198

164199
Floating point Not a Number. Signifies an error in a calculation.
165200
**NaN** is never equal to another **Number**, even if it is **NaN**.
166-
To check if something is **NaN**, use %%Global#isNaN|isNan()%%.
201+
To check if something is **NaN**, use
202+
%%Global#isNaN|isNan()%% or
203+
%%#isNaN|Number.isNan()%%.
167204
Also exists as %%Global#NaN|**NaN**%% in the global namespace.
168205

169206
<example>
@@ -208,3 +245,76 @@ console.log(1/0);
208245
Spec:
209246
http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.3.6
210247

248+
----
249+
isFinite(x : Number) : Boolean
250+
251+
Returns **true** if **x** is not **NaN**, **+Infinity**, or **-Infinity**.
252+
See also the global %%/Global#isFinite|**isFinite(x)**%% method.
253+
254+
<example>
255+
console.log(Number.isFinite(0/0)); // 0/0 is NaN
256+
console.log(Number.isFinite(1/0)); // 1/0 is infinity
257+
console.log(Number.isFinite(1.2)); // 1.2 is finite
258+
259+
console.log();
260+
261+
// Compare Number.isFinite and global isFinite methods
262+
console.log(Number.isFinite('0')); // The string '0' is not a Number
263+
console.log(isFinite('0')); // The string '0' is converted to a Number
264+
</example>
265+
266+
Version:
267+
ECMAScript 6
268+
269+
----
270+
isInteger(x : Number) : Boolean
271+
272+
Returns **true** if **x** is an integer.
273+
274+
<example>
275+
console.log(Number.isInteger(0));
276+
console.log(Number.isInteger(1.0));
277+
console.log(Number.isInteger(1.2));
278+
</example>
279+
280+
Version:
281+
ECMAScript 6
282+
283+
----
284+
isSafeInteger(x : Number) : Boolean
285+
286+
Returns **true** if **x** is greater than or equal to
287+
%%Number#MIN_SAFE_INTEGER|**MIN_SAFE_INTEGER**%%
288+
and less than or equal to
289+
%%Number#MAX_SAFE_INTEGER|**MAX_SAFE_INTEGER**%%.
290+
Adding or subtracting **1** to numbers outside this range may not
291+
produce a change in the value due to lack of floating point precision.
292+
293+
<example>
294+
console.log(Number.isInteger(42));
295+
console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER));
296+
console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1));
297+
</example>
298+
299+
Version:
300+
ECMAScript 6
301+
302+
----
303+
isNaN(x : Number) : Boolean
304+
305+
Returns **true** if **x** is %%/Number#NaN|**NaN**%%.
306+
**NaN** is never equal to another **Number**, even if it is **NaN**,
307+
so you must use **isNaN** to check for **NaN**.
308+
309+
See also the global %%/Global#isNaN|**isNaN(x)**%% method.
310+
311+
<example>
312+
var x = 0/0;
313+
console.log(x === NaN);
314+
console.log(Number.isNaN(x));
315+
316+
</example>
317+
318+
Version:
319+
ECMAScript 6
320+

0 commit comments

Comments
 (0)