![]() |
VOOZH | about |
Mathematical operations are among the most fundamental and universal features of any programming language. In JavaScript, numbers are used frequently for common tasks such as finding browser window size dimensions, getting the final price of a monetary transaction, and calculating the distance between elements in a website document.
Although a high-level understanding of mathematics is not a prerequisite to being a capable developer, it is important to know what types of operations are available in JavaScript, and how to use math as a tool to accomplish practical tasks.
Unlike other programming languages, JavaScript only has one number data type; there is no distinction made between integers (positive or negative whole numbers) and floats (numbers with a decimal point), for example.
In this tutorial, we will go over arithmetic operators, assignment operators, and the order of operations used with JavaScript number data types.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
JavaScript is a high-level, object-based, dynamic scripting language popular as a tool for making webpages interactive.
Browse Series: 37 tutorials
Software engineer and open source creator
Community and Developer Education expert. Former Senior Manager, Community at DigitalOcean. Focused on topics including Ubuntu 22.04, Ubuntu 20.04, Python, Django, and more.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Nice article. I think this example will better than when run in Console tab of browser.
let y = 7;
y++;
//result: 7
y++;
//result: 8
console.log(y);
//result: 9
Hi! What will be the explaination for this set of codes: var a = 10; var b = 10; sum = Math.log2(2a * 2b); console.log(sum); sum = 20;
Tania , your tutorials are very nice. In the addition and subtraction section Please include this example for scrollToId function.
<!DOCTYPE html> <html lang=“en”> <head> <meta charset=“UTF-8”> <title>Title</title> <style> div { border: 1px solid black; background-color: lightblue; height: 2000px; width: 2000px; } </style> </head> <body>
<button onclick=“myFunction()” style=“position:fixed;”>Click me to go down</button><br><br> <button onclick=“scrollToId()” style=“position:fixed;”>Click me to go up</button><br><br> <div></div>
<script> function scrollToId() { const navHeight = 100; window.scrollTo(0, window.pageYOffset - navHeight); }
function myFunction() { window.scrollTo(0, 100); alert("pageXOffset: " + window.pageXOffset + ", pageYOffset: " + window.pageYOffset); } </script>
</body> </html>
Thank you .
I think this explanation has a mistake(or ambiguity).
Set a variable
let y = 7;
// Use the prefix increment operation
let postfix = y++;
console.log(postfix);
Output
7
The value of y was not increased in the postfix operation. This is because the value will not be incremented until after the expression has been evaluated.
Actually, when using the postfix ++ operator the value of y gets updated but what is returned to the left-hand side is the old value of y.
let postfix=y++;
//can be thought of
//let postfix=y;
//y=y+1;
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.