Закрыть
×
=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
Праздники ...
Праздники ...
Рождество (Католическое) 25 Декабря
Концерты, выставки ...
Концерты, выставки ...
Спектакль "Особо опасные пенсионеры"|||г. Минск 6 сентября, 21 октября, 17 ноября 2026
Афишу
Спорт занятия ...
Спорт занятия ...
Занятия в тренажерном зале
Спорт занятие
Компьютер, программы...
Компьютер, программы...
Объявления ...
Объявления ...
ремонт двигателя ММЗ Д243Л-94 трактора МТЗ 80/82
Объявление
Новости ...
Новости ...
Форум ...
Форум ...
обсуждение...
<<
Поиск >>
Поиск
Концерты
Спорт
Форум
Компьютер
Компьютер, программы
→
JavaScript - programming language for HTML
Number in the JavaScript | standard ES5
посмотрели
11649
раз
обновлено: 1 Augusta 2020
To declare a numeric variable, you need to write:
var Name = 25;
or
var Name = 34.7;
or
var Name = Number(30);
or
var Name = new Number(30);
Example
Html
<script>
// Option 1. Integer
var
value1 = 45;
// Option 2. Fractional number
var
value2 = 23.56;
// Option 3. Class Number contains an integer
var
value3 = Number(
"45"
);
// Option 4. The Number class contains an integer
var
value3 = new Number(
"45"
);
</script>
Conversion string → to a fractional number
Html
<script>
// Converts to number (if all characters are numbers or dots)
var
value = Number(
"56.2"
);
// value = 56.2
var
value = Number(
"56.2 a"
);
// value = NaN
// Converts to number (if not all digit characters are)
var
value = parseFloat(
"123.45 a"
);
// value = 123.45
var
value = parseFloat(
"Hello 123.45 a"
);
// value = NaN
</script>
Conversion error, check after conversion Number.isNaN(...)
Html
Example
<script>
var
value = parseFloat(
"Hello 123.45 a"
);
// value = Nan
var
isError = Number.isNaN(value);
// isError = true
</script>
Conversion string → to an integer
Html
<script>
// Converts to number (if all characters are digits)
var
value = Number(
"56"
);
// value = 56
var
value = Number(
"56 a"
);
// value = NaN
// Converts to number (if not all digit characters are)
var
value = parseInt(
"82 dfg"
);
// value = 82
var
value = parseInt(
"a 82 dfg"
);
// value = NaN
</script>
Convert hexadecimal number → to a decimal number
Html
<script>
var
value = parseInt(
"0x23"
, 16);
// 16 it is a sixth-supratice system
// value = 35
</script>
Round a fractional number with decimal precision. Function toFixed
Html
<script>
var
value = Number(
"123.497"
);
var
fix = value.toFixed(2);
// round a number to 2 decimal places
// fix = 123.50
var
value = Number(
"56.2347"
);
// round a number to 2 decimal places
var
fix = value.toFixed(2);
// fix = 56.23
</script>
The integer part of the number. Function Math.floor
Html
<script>
var
value = 123.97;
var
newValue = Math.floor(value);
// newValue = 123
var
value = 56.2347;
var
newValue = Math.floor(value);
// newValue = 56
</script>
Round a fractional number to an integer. Function Math.round
Html
<script>
var
value = 123.97;
var
newValue = Math.round(value);
// newValue = 124
var
value = 56.2347;
var
newValue = Math.round(value);
// newValue = 56
</script>
Round a fractional number to an integer. Function Math.ceil
Html
<script>
var
value = 123.97;
var
newValue = Math.ceil(value);
// newValue = 124
var
value = 56.001;
var
newValue = Math.ceil(value);
// newValue = 57
</script>
Number modulus (if the number negative becomes positive). Function Math.abs
Html
<script>
var
value = -123.97;
var
newValue = Math.abs(value);
// newValue = 123.97
var
value = 56.001;
var
newValue = Math.abs(value);
// newValue = 56.001
</script>
All Features Number
msdn.microsoft.com
← Previous topic
Write a regular expression to remove all special characters except letters and numbers | Regex JavaScript | standard ES5
Next topic →
Mathematical functions from the library Math: Sin, cos, log, pow and so on in the JavaScript | standard ES5
Your feedback ... Comments ...
Your Name
Your comment
(www links can only be added by a logged-in user)
+ Picture
Новость
"Черная пятница" на технику Dreame в Беларуси с 17 по 30 ноября 2026 года – две недели скидок до 3400 рублей
•
In which editor (program) is it convenient to write JavaScript code?
New app
•
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
Debugging JavaScript, HTML
•
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
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
Unnamed function
•
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
Self-calling unnamed function
•
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
Lambda function (abbreviated version of the unnamed function)
•
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
Variables
•
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
Regular expressions
•
Regular expressions in JavaScript | ES5 standard
•
Write a regular expression to remove all special characters except letters and numbers | Regex JavaScript | standard ES5
Numbers and mathematical functions
•
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
Date & Time
•
Date & Time (year, month, date, hours, minutes, seconds) in the JavaScript. Class Date | standard ES5
Array
•
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
Collection Map and Set
•
Collection "The key-meaning" in the JavaScript. Class Map | standard ES5
•
Collection of unique values in the JavaScript. Class Set | standard ES5
Object {set of properties and functions}
•
{} 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
Class (it is a function using new) | ES5 standard
•
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
try catch
•
Why you need to use try and catch in the JavaScript? | standard ES5
Closing (closure) in the Javascript
•
What are closures? (closure) in the JavaScript ? Standard ES5
Memory management in JavaScript
•
Memory management in JavaScript | ES5 standard
Examples of picture movement and animation
•
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
Examples
•
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