

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to do basic Maths with JavaScript Operators?
To do basic Maths such as +, -, * in JavaScript, use the Operators. JavaScript includes operators for basic mathematics such as Addition, Subtraction, Multiplication, etc.
Example
You can try to run the following code to learn how to work with basic Maths i.e. Mathematical Operators in JavaScript −
<html> <body> <script> var a = 77; var b = 30; var c = "Demo"; var linebreak = "<br />"; document.write("a + b = "); result = a + b; document.write(result); document.write(linebreak); document.write("a - b = "); result = a - b; document.write(result); document.write(linebreak); document.write("a / b = "); result = a / b; document.write(result); document.write(linebreak); document.write("a % b = "); result = a % b; document.write(result); document.write(linebreak); document.write("a + b + c = "); result = a + b + c; document.write(result); document.write(linebreak); a = ++a; document.write("++a = "); result = ++a; document.write(result); document.write(linebreak); b = --b; document.write("--b = "); result = --b; document.write(result); document.write(linebreak); </script> </body> </html>
- Related Questions & Answers
- What are basic JavaScript mathematical operators?
- How to do basic form validation using JavaScript?
- Basic operators in Java
- Basic Operators in Python
- Basic Operators in Relational Algebra
- Basic Operators in Shell Scripting
- What are different basic operators in Python?
- How to implement basic Animation in JavaScript?
- How to do image preloading with javascript?
- How do conversion operators work in C++?
- JavaScript Basic Array Methods
- Write a C# program to do basic arithmetic calculations
- How can we do the basic print formatting for Python numbers?
- How to remove random unwanted space in LaTeX-style maths in matplotlib plot?
- Create a to-do list with JavaScript
Advertisements