Exemples JavaScript

Nombre JavaScript

Les nombres peuvent être écrits avec ou sans point décimal
Il est possible d'écrire des nombres extrêmement grands ou extrêmement petits en utilisant le système de notation exponentielle
Les nombres sont arrondis à 15 chiffres
L'arithmétique flottante n'est pas toujours 100% précise
Mais ce problème peut être résolu en multipliant et en divisant par 10
L'addition de deux nombres produit un nouveau nombre
L'addition de deux chaînes de nombres produit une chaîne de caractères
L'addition de nombres et de chaînes de nombres produit également une chaîne de caractères
L'addition de chaînes de nombres et de nombres produit également une chaîne de caractères
Erreur courante lors de l'addition de chaînes de caractères et de nombres 1
Common error 2 when adding strings and numbers
In division operations, JavaScript will try to convert strings to numbers
In multiplication operations, JavaScript will try to convert strings to numbers
In subtraction operations, JavaScript will try to convert strings to numbers
In addition operations, JavaScript will not convert strings to numbers
The number divided by a string is no longer a number
Dividing a number by a numeric string results in a number
The global JavaScript function isNaN() determines whether a value is a number
Using NaN in mathematical operations will always return NaN
Using NaN in mathematical string operations will connect NaN
The type of NaN is number (no! typeof NaN returns number)
If a number outside the maximum possible number is calculated, it returns infinity (Infinity)
Division by zero generates Infinity
Infinity is also a number (typeof Infinity returns number)
Constants prefixed with 0x are interpreted as hexadecimal
The toString() method can output numbers in hexadecimal, octal, or binary
Numbers can be objects
Numbers and objects cannot be safely compared
Objects and objects cannot be safely compared

Example explanation: numbers