let myNumber = 42;
console.log(myNumber); // Output: 42
In this example, we declare a variable called `myNumber` and assign the value `42` to it. We can then use the `console.log()` function to display the value of `myNumber` in the console.
let x = 5;
let y = 2;
console.log(x + y); // Output: 7
console.log(x – y); // Output: 3
console.log(x * y); // Output: 10
console.log(x / y); // Output: 2.5
console.log(x % y); // Output: 1
In this example, we perform different arithmetic operations using the variables `x` and `y`. The results are displayed using `console.log()`.
– `Number.NaN`: Represents a value that is Not-a-Number.POSITIVE_INFINITY`: Represents positive infinity.NEGATIVE_INFINITY`: Represents negative infinity.
console.log(Number.MAX_VALUE); // Output: 1.7976931348623157e+308
console.MIN_VALUE); // Output: 5e-324
console.NaN); // Output: NaN
console.POSITIVE_INFINITY); // Output: Infinity
console.NEGATIVE_INFINITY); // Output: -Infinity
In this example, we access and display the values of different properties related to numbers.
– `toString()`: Converts a number to a string. – `toFixed()`: Formats a number using fixed-point notation.
– `toPrecision()`: Formats a number to a specified precision. – `parseInt()`: Parses a string and returns an integer.
let myNum = 3.14159;
console.log(myNum.toString()); // Output: “3.14159”
console.toFixed(2)); // Output: “3.14”
console.toPrecision(4)); // Output: “3.142”
console.log(parseInt(“42”)); // Output: 42
In this example, we use different methods to manipulate and format the number stored in the variable `myNum`.