Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Math in JavaScript

Js Math in JavaScript

? JavaScript Math Object

The Math object in JavaScript provides built-in properties and methods for mathematical constants and functions. It’s not a function, but a static object you can use directly.


? Common Math Properties

PropertyDescriptionExample
Math.PI? (pi) constant3.141592653589793
Math.EEuler’s number (e)2.718281828459045
Math.LN2Natural log of 20.6931471805599453
Math.LN10Natural log of 102.302585092994046
Math.SQRT2Square root of 21.4142135623730951

? Common Math Methods

MethodDescriptionExample
Math.abs(x)Absolute valueMath.abs(-5); // 5
Math.round(x)Rounds to nearest integerMath.round(4.7); // 5
Math.floor(x)Rounds down (floor)Math.floor(4.7); // 4
Math.ceil(x)Rounds up (ceiling)Math.ceil(4.1); // 5
Math.max(a, b, ...)Returns max of argumentsMath.max(3, 7, 2); // 7
Math.min(a, b, ...)Returns min of argumentsMath.min(3, 7, 2); // 2
Math.pow(x, y)x raised to the power yMath.pow(2, 3); // 8
Math.sqrt(x)Square rootMath.sqrt(16); // 4
Math.random()Returns random float between 0-1Math.random(); // e.g., 0.234
Math.sin(x)Sine of x (x in radians)Math.sin(Math.PI / 2); // 1
Math.cos(x)Cosine of xMath.cos(0); // 1

? Example: Random Integer Between Two Values

function getRandomInt(min, max) {  min = Math.ceil(min);  max = Math.floor(max);  // The maximum and minimum are inclusive  return Math.floor(Math.random() * (max - min + 1)) + min;}console.log(getRandomInt(1, 10)); // random int between 1 and 10

Would you like me to show examples for any specific Math methods or formulas?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql