πŸ“˜
NavDoc by Bash School
GithubContact
πŸ“˜
NavDoc by Bash School
  • πŸŽ“Introduction
  • 🐒Getting Started
  • ⚑Changelog
  • πŸ‘¨β€πŸš€Maintainers
  • πŸ›£οΈRoadmap
  • Fundamentals
    • The Internet
      • Introduction
      • What is a URL
      • What is a port
      • The DNS protocol
      • The TCP protocol
      • The UDP protocol
      • The Web
      • The HTTP protocol
      • Hyperlinks
      • What is a Web browser
      • What is a Web server
    • HTML
      • Your first HTML page
      • Text tags
      • Attributes
      • Links
      • Images
      • Lists
      • Head Tags
      • Container tags
    • CSS
      • Introduction
      • Colors
      • selectors
      • Cascade
      • Specificity
      • Units
      • Advanced selectors
      • Typography
      • The box model
      • The display property
      • Responsive design
  • JavaScript
    • Basics
      • Introduction
      • Literals , Identifiers, Variables
      • Comments
      • The difference between let, const and var
      • Types
      • Operators and expressions
      • Arithmetic operators
      • The assignment operator
      • Operators precedence
      • Strings
      • Numbers
      • Semicolons, white space and sensitivity
      • Arrays
      • Conditionals
      • Loops
      • Functions
      • Objects
      • Arrays + functions
      • OOPS
      • Asynchronous
      • Scope, hoisting, event loop
      • ES Modules
      • Errors and exceptions
      • Built-in objects
        • The global object
        • Object properties
        • Number
        • String
        • Math
        • JSON
        • Date
        • Intl
        • Set and Map
      • More operators
    • Nodejs
      • Getting Started
      • Installation
      • Hello World in Node
      • Modules
      • Packages
      • File Handling
      • HTTP Request
      • Processing Files
      • HTTP
    • Express.js
      • Getting Started
      • Middleware
      • Serve Static Assets
      • How to Send Files to the Client
      • Sessions
      • Validate Input
      • Sanitizing Data
      • Forms
      • File Uploads
    • React
      • Setting up a React project with Vite
      • React Components
      • Introduction to JSX
      • Using JSX to compose UI
      • The difference between JSX and HTML
      • Embedding JavaScript in JSX
      • Handling user events
      • Managing state
      • Component props
      • Data flow
      • Lifecycle events
      • Managing forms in React
      • Install the React Developer Tools
      • Installing Tailwind CSS in a React app
      • Build a counter in React
    • TypeScript
      • Key Benefits
      • Types of Languages
      • The Need for TypeScript
      • What is TypeScript?
      • The tsc Compiler
      • Basic Types in TypeScript
      • tsconfig
      • Interfaces
      • Types
      • Arrays in TypeScript
      • Enums
      • Exporting and importing
    • MongoDB
      • SQL vs. NoSQL Databases
      • Installing MongoDB
      • MongoDB Databases and Collections
      • Working with Documents
      • MongoDB Operators
      • Sorting, Indexing & Searching
      • Built-in Methods
Powered by GitBook
On this page
  • Properties
  • Methods

Was this helpful?

Edit on GitHub
  1. JavaScript
  2. Basics
  3. Built-in objects

Math

The Math object contains lots of math-related utilities.

It provides us a lot of properties and functions that we can use to perform calculations.

Properties

  • Math.E e, base of the natural logarithm (means ~2.71828)

  • Math.LN10 represents the base e (natural) logarithm of 10

  • Math.LN2 represents the base e (natural) logarithm of 2

  • Math.LOG10E represents the base 10 logarithm of e

  • Math.LOG2E represents the base 2 logarithm of e

  • Math.PI the Ο€ constant (~3.14159)

  • Math.SQRT1_2 represents the reciprocal of the square root of 2

  • Math.SQRT2 represents the square root of 2

Methods

All those methods are static.

Math.abs()

Returns the absolute value of a number

Math.abs(2.5) //2.5
Math.abs(-2.5) //2.5

Math.acos()

Returns the arccosine of the operand

The operand must be between -1 and 1

Math.acos(0.8) //0.6435011087932843

Math.asin()

Returns the arcsine of the operand

The operand must be between -1 and 1

Math.asin(0.8) //0.9272952180016123

Math.atan()

Returns the arctangent of the operand

Math.atan(30) //1.5374753309166493

Math.atan2()

Returns the arctangent of the quotient of its arguments.

Math.atan2(30, 20) //0.982793723247329

Math.ceil()

Rounds a number up

Math.ceil(2.5) //3
Math.ceil(2) //2
Math.ceil(2.1) //3
Math.ceil(2.99999) //3

Math.cos()

Return the cosine of an angle expressed in radiants

Math.cos(0) //1
Math.cos(Math.PI) //-1

Math.exp()

Return the value of Math.E multiplied per the exponent that’s passed as argument

Math.exp(1) //2.718281828459045
Math.exp(2) //7.38905609893065
Math.exp(5) //148.4131591025766

Math.floor()

Rounds a number down

Math.floor(2.5) //2
Math.floor(2) //2
Math.floor(2.1) //2
Math.floor(2.99999) //2

Math.log()

Return the base e (natural) logarithm of a number

Math.log(10) //2.302585092994046
Math.log(Math.E) //1

Math.max()

Return the highest number in the set of numbers passed

Math.max(1,2,3,4,5) //5
Math.max(1) //1

Math.min()

Return the smallest number in the set of numbers passed

Math.max(1,2,3,4,5) //1
Math.max(1) //1

Math.pow()

Return the first argument raised to the second argument

Math.pow(1, 2) //1
Math.pow(2, 1) //2
Math.pow(2, 2) //4
Math.pow(2, 4) //16

Math.random()

Returns a pseudorandom number between 0.0 and 1.0

Math.random() //0.9318168241227056
Math.random() //0.35268950194094395

Math.round()

Rounds a number to the nearest integer

Math.round(1.2) //1
Math.round(1.6) //2

Math.sin()

Calculates the sin of an angle expressed in radiants

Math.sin(0) //0
Math.sin(Math.PI) //1.2246467991473532e-16)

Math.sqrt()

Return the square root of the argument

Math.sqrt(4) //2
Math.sqrt(16) //4
Math.sqrt(5) //2.23606797749979

Math.tan()

Calculates the tangent of an angle expressed in radiants

Math.tan(0) //0
Math.tan(Math.PI) //-1.2246467991473532e-16
PreviousStringNextJSON

Last updated 1 year ago

Was this helpful?