Закрыть
×
=0) { let js = text.slice(pos1, pos2); + '<\/' + "script" + '>'; arrText.push(js); // next pos1 = pos2; continue; } } } break; } return arrText; } function OpenDialog(parentDiv, urlContent) { parentDiv = document.getElementById('modal-background'); // new !!!!!!! parentDiv.appendChild(document.getElementById('modal-template')); document.getElementById('modal-background').style.display = "flex"; // !!!!! block document.getElementById('modal-template').style.display = "flex"; // !!!!! document.getElementById('modal-body').innerHTML = ""; post_url(urlContent, "", function(text_from_server) { var element = document.getElementById('modal-body'); element.innerHTML = text_from_server; // add scripts var arrJSText = get_scripts(text_from_server); for (var i=0; i
dir.by
Праздники ...
Праздники ...
День города Минска (2-ая суббота сентября) (9 и 10 сентября 2023)
Концерты, выставки ...
Концерты, выставки ...
Вадим Самойлов "Агата Кристи"|||г. Минск 19 декабря 2026
Афишу
Спорт занятия ...
Спорт занятия ...
Играем в баскетбол, волейбол, гандбол, мини-футбол
Спорт занятие
Компьютер, программы...
Компьютер, программы...
Объявления ...
Объявления ...
Механизм рулевой для грузовых автомобилей УАЗ ШНКФ 453461.136
Объявление
Новости ...
Новости ...
Форум ...
Форум ...
обсуждение...
Поиск
Концерты
Спорт
Форум
Компьютер
Компьютер, программы
→
JavaScript - programming language for HTML
JavaScript mathematical functions from the library Math: sin, cos, log, pow and so on | standard ES5
посмотрели
11651
раз
обновлено: 1 Augusta 2020
Content
Functions for the circumference...
Math.E
Math.PI
Math.cos(value1)
Math.sin(value1)
Math.tan(value1)
Math.acos(value1)
Math.asin(value1)
Math.atan(value1)
Math.atan2(value1, value2)
Math.cosh(x)
Math.sinh(x)
Math.tanh(value1)
Math.acosh(value1)
Math.asinh(value1)
Math.atanh(value1)
Rounding numbers...
Math.sign(value1)
Math.random(value1)
Math.abs(value1)
Math.min(value1, value2, ...)
Math.max(value1, value2, ...)
Math.ceil(value1)
Math.floor(value1)
Math.round(value1)
Math.trunc(value1)
Exponentiation, root, logarithms...
Math.exp(value1)
Math.log(x)
Math.log10(x)
Math.log2(x)
Math.log1p(y)
Math.expm1(value1)
Math.hypot(value1, value2, ...)
Math.imul(value1, value2)
Math.pow(x, y)
Math.sqrt(x)
Functions for the circle: sin, cos, and so on
Math.E
Constant, base of natural logarithms
Html
Example
<script>
var
result = Math.E;
// result = 2.718281828459045
</script>
Math.PI
Constant
the ratio of the circumference of the circle to its diameter
It corresponds to 180 degree
Html
Example
<script>
var
result = Math.PI;
// result = 3.141592653589793
</script>
Math.cos
(value1)
returns the cosine of a number
value1 set in radians
Html
Example
<script>
var
result = Math.cos(3.14);
// result = -1
</script>
pi=3.14 (This is 180 Degrees)
Math.sin
(value1)
returns the sine of a number
value1 set in radians
Html
Example
<script>
var
result = Math.sin(3.14);
// result = 0
</script>
pi=3.14 (This is 180 Degrees)
Math.tan
(value1)
returns the tangent of a number
value1 set in radians
Html
Example
<script>
var
result = Math.tan(3.14/4);
// result = 1;
</script>
pi=3.14 (This is 180 Degrees)
pi/4 (This is 45 Degrees)
Math.acos
(value1)
returns arccosine number
Html
Example
<script>
var
result = Math.acos(-1);
// result = 3.14159
</script>
Math.asin
(value1)
returns the arc sine of a number
Html
Example
<script>
var
result = Math.asin(-1);
// result = -1.57
</script>
Math.atan
(value1)
returns the arctangent of a number
Html
Example
<script>
var
result = Math.atan(-1);
// result = -0.7853
</script>
Math.atan2
(value1, value2)
returns the angle (in radians) from the x-axis to the point corresponding to the specified X and Y coordinates
Html
Example
<script>
var
result = Math.atan2(0.2, 5);
// result = 0.0399
</script>
Math.cosh
(x)
returns the hyperbolic cosine of a number
e
x
+ e
-x
= e
2x
+ 1
Math.sinh
(x)
returns the hyperbolic sine of a number
e
x
- e
-x
= e
2x
- 1
Math.tanh
(value1)
returns the hyperbolic tangent of a number
sinh(x) / cosh(x)
Math.acosh
(value1)
Returns the hyperbolic arccosine of a number (inverse of the hyperbolic cosine of a number)
Math.asinh
(value1)
Returns the hyperbolic arc sine of a number (inverse hyperbolic sine of a number)
Math.atanh
(value1)
Returns the hyperbolic arc-tangent of a number (inverse hyperbolic tangent of a number)
Rounding numbers
Math.sign
(value1)
returns a number sign
1 or -1 or 0
that is, whether the number is positive or negative or zero
Html
Example
<script>
var
result = Math.sign(6);
// result = 1;
result = Math.sign(-6);
// result = -1;
result = Math.sign('-6');
// result = -1;
result = Math.sign(0);
// result = 0;
</script>
Math.random
(value1)
returns a random number from 0 to 1
Html
Example
<script>
var
result = Math.random();
// result = 0.02
result = Math.random();
// result = 0.05
result = Math.random();
// result = 0.334524
</script>
Math.abs
(value1)
returns the absolute value of a number
Html
Example
<script>
var
result = Math.abs(-123.97);
// result = 123.97
</script>
Math.min
(value1, value2, ...)
returns the smallest of the values
Html
Example
<script>
var
result = Math.min(5, 67, 15, 430, 2);
// result = 2
</script>
Math.max
(value1, value2, ...)
returns more of the values
Html
Example
<script>
var
result = Math.max(5, 67, 15, 430, 2);
// result = 430
</script>
Math.ceil
(value1)
Rounds up a number (the new number will be greater than or equal to the specified number)
Html
Example
<script>
var
result = Math.ceil(3.6);
// result = 4
result = Math.ceil(3.1);
// result = 4
result = Math.ceil(3.001);
// result = 4
result = Math.ceil(3.00);
// result = 3
result = Math.ceil(-3.00);
// result = -3
result = Math.ceil(-3.001);
// result = -3
result = Math.ceil(-3.1);
// result = -3
var
result = Math.ceil(-3.6);
// result = -3
</script>
Math.floor
(value1)
Rounds the number down (the new number will be less than or equal to the specified number)
Html
Example
<script>
var
result = Math.floor(3.6);
// result = 3
result = Math.floor(3.1);
// result = 3
result = Math.floor(3.001);
// result = 3
result = Math.floor(3.00);
// result = 3
result = Math.floor(-3.00);
// result = -3
result = Math.floor(-3.001);
// result = -4
result = Math.floor(-3.1);
// result = -4
var
result = Math.floor(-3.6);
// result = -4
</script>
Math.round
(value1)
Rounds up to the nearest number
Html
Example
<script>
var
result = Math.round(3.6);
// result = 4
result = Math.round(3.1);
// result = 3
result = Math.round(3.001);
// result = 3
result = Math.round(3.00);
// result = 3
result = Math.round(-3.00);
// result = -3
result = Math.round(-3.001);
// result = -3
result = Math.round(-3.1);
// result = -3
var
result = Math.round(-3.6);
// result = -4
</script>
Math.trunc
(value1)
returns the integer part of the number, discarding the fractional part
Html
Example
<script>
var
result = Math.trunc(12.48);
// result = 12;
result = Math.trunc(-12.48);
// result = -12;
result = Math.trunc(0.23);
// result = 0;
result = Math.trunc(-0.23);
// result = 0;
</script>
Exponentiation, root, logarithms
Math.exp
(value1)
e
x
(raises e to power x) Where is e=2.71827 (base of natural logarithms)
Html
Example
<script>
var
result = Math.exp(3);
// result = 2.71827
3
= 20.085
</script>
Math.log
(x)
y=
log(x)
(returns the natural logarithm of a number)
it can be represented as follows
x = e
y
e=2.71827 (base of natural logarithms)
Html
Example
<script>
var
result = Math.log(20.085);
// result = 3
</script>
Math.log10
(x)
log10(x)
(returns the logarithm of a number at base 10)
Html
Example
<script>
var
result = Math.log10(1000);
// result = 3
</script>
Math.log2
(x)
log2(x)
(returns the logarithm of a base number 2)
Html
Example
<script>
var
result = Math.log2(16);
// result = 4
</script>
Math.log1p
(y)
log (y+1)
Html
Example
<script>
var
result = Math.log1p(20.085);
// result = log(20.085 + 1) = log(21.085) = 3.048561887
</script>
Math.expm1
(value1)
e
x
- 1
(raises e to power x - 1)
e=2.71827 (base of natural logarithms)
Html
Example
<script>
var
result = Math.expm1(3.048561887);
// result = 2.71827
3.048561887
- 1 = 20.085
</script>
Math.hypot
(value1, value2, ...)
sqrt(value1*value1 + value2*value2 + ...) that is, returns the square root of the sum of the squares of the arguments
Html
Example
<script>
var
result = Math.hypot(3, 4, 6, 9);
// result = sqrt(3*3 + 4*4) = sqrt(25) = 5
result = Math.hypot(3, 4, 9);
// result = sqrt(3*3 + 4*4 + 9*9) = sqrt(106) = 10.295
</script>
Math.imul
(value1, value2)
value1 * value2 (product of two numbers)
Html
Example
<script>
var
result = Math.imul(3, 4);
// result = 3 * 4 = 12
</script>
Math.pow
(x, y)
x
y
(raises x to the power of y)
Html
Example
<script>
var
result = Math.pow(3, 2);
// result = 3*3 = 9
</script>
Math.sqrt
(x)
square number root x
Html
Example
<script>
var
result = Math.sqrt(16);
// result = 4;
</script>
Learn more
msdn.microsoft.com
← Previous topic
Number in the JavaScript. Convert text to a number. Rounding a number. Convert hexadecimal to decimal. | standard ES5
Next topic →
Date & Time (year, month, date, hours, minutes, seconds) in the JavaScript. Class Date | standard ES5
Your feedback ... Comments ...
Your Name
Your comment
(www links can only be added by a logged-in user)
+ Picture
Объявления
Объявления
•
In which editor (program) is it convenient to write JavaScript code?
[bgcolor=#D0F2A0]New app[/bgcolor]
•
Create a new application JavaScript in a text editor
•
Create a new application JavaScript in Visual Studio Code. Debug the application. See in debugging how to perform JavaScript
[bgcolor=#D0F2A0]Debugging JavaScript, HTML[/bgcolor]
•
Debug JavaScript in Google Chrome. Using debugger
•
How to find out (see) where the error is when executing HTML, JavaScript in Google Chrome
•
Debugging JavaScript in the Google Chrome. Use console.log("Hello!")
JavaScript standard ES5. It was published in 2009. Supported by all browsers
[bgcolor=#D0F2A0]Function
•
Function in the JavaScript. Example: function CalculateSum(value1, value2) { ... } | standard ES5
•
Function return || in the JavaScript. Example: function getPersonName(name) { return name || "Evgen" } | standard ES5
•
Call a function before it is defined (Hoisting) in the JavaScript | standard ES5
•
Variables within a function (lifetime of variables within a function) JavaScript | standard ES5
•
Pass parameters by value and by reference to the function in the JavaScript | standard ES5
•
How to find out... whether there is a function by name in the JavaScript? Example: typeof calcSum == "function" | standard ES5
•
The function described inside the function. JavaScript | standard ES5
[bgcolor=#D0F2A0]Unnamed function[/bgcolor]
•
Unnamed function in the JavaScript . Using an unnamed function: create a new variable and assign an unnamed function to a new variable. Example: var myFunc1 = function (a, b) { return a + b; } ; | standard ES5
•
Unnamed function in the JavaScript . Using an unnamed function: pass an unnamed function as a parameter to another function. Example: Calculate(15, 7, function(v1, v2) {return v1+v2;}); | standard ES5
[bgcolor=#D0F2A0]Self-calling unnamed function[/bgcolor]
•
Self-calling unnamed function in the JavaScript. Where is it used? Used in Yandex advertising. Example: ( function(){ ... } )(); | standard ES5
•
Create a file js with an object containing export variables and functions. This is an example of using a self-calling unnamed function | standard ES5
[bgcolor=#D0F2A0]Lambda function (abbreviated version of the unnamed function)[/bgcolor]
•
Lambda function in the JavaScript . Use the lambda function. [Example1] var myFunc1 = (a, b) => a + b; [Example2] Calculate(15, 7, (v1, v2) => {return v1+v2;}); | standard ES5
[bgcolor=#D0F2A0]Variables[/bgcolor]
•
Variables in the JavaScript (text, number, flag, date and time) | standard ES5
•
Accessing Variables Before Defining Them (Hoisting) in the JavaScript | standard ES5
•
Variable scope var, let, const in the JavaScript | standard ES5
Text, strings in the JavaScript
•
Text in the JavaScript. Class String. Example: var myText = String("World"); | standard ES5
•
Length (string length in the JavaScript) | standard ES5
•
Function replace(text1, text2) replace text in the JavaScript | standard ES5
•
Function toUpperCase() converts text to uppercase JavaScript | standard ES5
•
Function toLowerCase() lowercase text JavaScript | standard ES5
•
Function split(delimiter) splits a string into substrings JavaScript | standard ES5
•
Function charAt(position) get a symbol by position JavaScript | standard ES5
•
Function substr(pos, len) returns a substring JavaScript | standard ES5
•
Function slice(pos1, pos2) returns a substring JavaScript | standard ES5
•
Function substring(pos1, pos2) returns a substring JavaScript | standard ES5
•
Function indexOf(text, startPos) searches for a substring and returns an index JavaScript | standard ES5
•
Function startsWith(text) Checks, whether the line begins with the specified substring JavaScript | standard ES5
•
Function trim() remove spaces at the beginning and end of a line JavaScript | standard ES5
•
The padStart(length, symbol) function appends characters at the beginning of a line up to the desired JavaScript line length | ES5 standard
•
The padEnd(length, symbol) function appends characters at the end of a line up to the desired JavaScript line length | ES5 standard
•
You can assign text as many lines to a text variable. Example: var myText = `Hello \n Thanks \n Bye` | JavaScript ES6 standard
•
In a text variable, you can write expressions with variables (formatting, string interpolation). Example: var myText = `Hello ${a}` | JavaScript standard ES6
[bgcolor=#D0F2A0]Regular expressions[/bgcolor]
•
Regular expressions in JavaScript | ES5 standard
•
Write a regular expression to remove all special characters except letters and numbers | Regex JavaScript | standard ES5
[bgcolor=#D0F2A0]Numbers and mathematical functions[/bgcolor]
•
Number in the JavaScript. Convert text to a number. Rounding a number. Convert hexadecimal to decimal. | standard ES5
•
Mathematical functions from the library Math: Sin, cos, log, pow and so on in the JavaScript | standard ES5
[bgcolor=#D0F2A0]Date & Time[/bgcolor]
•
Date & Time (year, month, date, hours, minutes, seconds) in the JavaScript. Class Date | standard ES5
[bgcolor=#D0F2A0]Array[/bgcolor]
•
Array in the JavaScript This is [] or class Array | standard ES5
•
What does 3 dots mean... items | Example 1: Math.max(... prices) | Example 2: books.push(... items) | JavaScript, ES5 standard
•
Difference between push(items) and push(...items) | Adding an Array to an Array in the JavaScript | standard ES5
•
Find max prices in a complex array: [ {name:"Tomate", price:10}, {name:"Apple", price:17}, {name:"Orange", price:15} ] in JavaScript | ES5 standard
•
Find min prices in a complex array: [ {name:"Tomate", price:10}, {name:"Apple", price:17}, {name:"Orange", price:15} ] in JavaScript | ES5 standard
[bgcolor=#D0F2A0]Collection Map and Set[/bgcolor]
•
Collection "The key-meaning" in the JavaScript. Class Map | standard ES5
•
Collection of unique values in the JavaScript. Class Set | standard ES5
[bgcolor=#D0F2A0]Object {set of properties and functions}[/bgcolor]
•
{} it"s an object in the JavaScript. An object contains a set of properties and functions. Example var book = {Name: "Wizard of the Mediterranean", Price: 120}; | standard ES5
•
{...} = object in JavaScript is populated from class variables or another object. Example: const {name, total, price} = b.myProps; | ES5 standard
[bgcolor=#D0F2A0]Class (it is a function using new) | ES5 standard[/bgcolor]
•
Class in the JavaScript this is a common constructor function. Such a constructor function contains simple data, objects, internal functions in the JavaScript. To create a class object, use new Example: function Book() { ... } ... var obj1 = new Book(); | ES5 standard
•
Encapsulating variables (hiding variables for access) in the function (as a class) in the JavaScript | standard ES5
•
prototype - is a set of functions, variables for all instances of the class (as a function) in the JavaScript | standard ES5
[bgcolor=#D0F2A0]try catch[/bgcolor]
•
Why you need to use try and catch in the JavaScript? | standard ES5
[bgcolor=#D0F2A0]Closing (closure) in the Javascript[/bgcolor]
•
What are closures? (closure) in the JavaScript ? Standard ES5
[bgcolor=#D0F2A0]Memory management in JavaScript[/bgcolor]
•
Memory management in JavaScript | ES5 standard
[bgcolor=#D0F2A0]Examples of picture movement and animation[/bgcolor]
•
Animation of the little man on the spot. Use the HTML element <div>. For animation, we use CSS styles: "animation", "background-image", "background-position", "keyframes" | ES5 standard
•
Animation of a man in motion (sprite). Use HTML elements <div>, <img>. For animation, we use CSS styles: "animation", "background-image", "background-position", "keyframes" | ES5 standard
•
Draw a picture with movement. Use the HTML element<canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval | standard ES5
•
Drawing a picture with movement and animation (sprite). Use the HTML element <canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval | standard ES5
[bgcolor=#D0F2A0]Examples[/bgcolor]
•
How to identify a device (tablet, computer, phone) that is currently used in JavaScript, HTML | ES5 standard
•
Text Editor write in HTML, JavaScript | standard ES5
Do Popup using HTML and Javascript
•
How to make a Popup window in a HTML page | Javascript, HTML, CSS
My Game (HTML, JavaScript)
•
My game "Wizard World" | HTML, JavaScript
PDF readers. Upload and display a PDF file (JavaScript, HTML)
•
PDF reader. Download and display a PDF file (adobe JavaScript, HTML) | PDF JavaScript implemented by Adobe
•
PDF reader. Download and display a file PDF (JavaScript, HTML) | PDF JavaScript implemented by Mozilla
JavaScript standard ES6. It was published in 2015. Not supported by all browsers. Synonyms ES6, ES2015, ECMAScript 2015
•
In a text variable, you can write expressions with variables (formatting, string interpolation). Example: var myText = `Hello ${a}` | JavaScript standard ES6
•
class | Class in the JavaScript. Example: class Book {...} ... var obj1 = new Book(); | ES6 standard
•
promise in the JavaScript | standard ES6
Ваши вопросы присылайте по почте:
info@dir.by