Science Knowings: JavaScript Course For Social Media

Working with Numbers

Summary of Working with Strings

In our previous session, we delved into the world of strings. We explored how to create, manipulate, and concatenate strings.

Different Number Types in JavaScript

JavaScript supports different number types, including integers, floats, and special numeric values like Infinity and NaN (Not a Number).

Numeric Literals

Numeric literals are numbers written in code without quotes. They can be integers (e.g., 123) or floating-point numbers (e.g., 12.34).

Arithmetic Operators

JavaScript provides arithmetic operators (+, -, *, /, %) to perform mathematical operations on numbers. These operators follow the order of operations (PEMDAS).

Increment and Decrement Operators

The ++ and -- operators increment or decrement a number by 1. They can be used as prefix (++num) or postfix (num++) operators.

Number Methods

Number.MAX_VALUE
Number.MIN_VALUE
Number.NaN
Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY
Number.isFinite()
Number.isNaN()
Number.isInteger()
Number.parseFloat()
Number.parseInt()

Number Properties

Numbers have properties like .toString() and .valueOf() that can be used to convert a number to a string or get its primitive value.

Global Number Object

The global Number object provides properties and methods for working with numbers (e.g., Number.MAX_VALUE, Number.MIN_VALUE).

Working with Math Object

Math.PI
Math.E
Math.sqrt()
Math.pow()
Math.sin()
Math.cos()
Math.tan()
Math.abs()
Math.ceil()
Math.floor()
Math.round()
Math.random()

parseInt() and parseFloat()

The parseInt() and parseFloat() functions convert strings to integers and floating-point numbers, respectively.

toExponential()

The toExponential() method converts a number to a string in exponential notation.

toFixed()

The toFixed() method converts a number to a string with a specified number of decimal places.

toPrecision()

The toPrecision() method converts a number to a string with a specified number of significant digits.

toString()

The toString() method converts a number to a string in its default radix (usually base 10).

valueOf()

The valueOf() method returns the primitive value of a number.

Next Topic: Working with Booleans

Booleans are fundamental to programming. In the next session, we'll learn about their importance, how to use them, and the operations we can perform on them. Follow us for more!