
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to write a JavaScript function to get the difference between two numbers?
Use Math.abs() inside a JavaScript function to get the difference between two numbers in JavaScript.
Example
You can try to run the following code to get the difference of numbers
<html> <head> <script> var num1, num2; num1 = 50; num2 = 35; var difference = function (num1, num2){ return Math.abs(num1 - num2); } document.write("Difference = "+difference(num1,num2)); </script> </head> <body></body> </html>
- Related Articles
- How to get the difference between two arrays in JavaScript?
- How to generate random numbers between two numbers in JavaScript?
- How to get the difference between two dates in Android?
- How to calculate the difference between two dates in JavaScript?
- How to find absolute difference between two numbers in MySQL?
- C# Program to get the difference between two dates
- How to get time difference between two timestamps in seconds?
- Get the property of the difference between two objects in JavaScript
- How to write a function to get the time spent in each function in Python?
- How to get the difference between two columns in a new column in MySQL?
- Write a program to calculate the least common multiple of two numbers JavaScript
- How to get substring between two similar characters in JavaScript?
- Not able to get the difference between two dates (SAP)
- How to get the number of seconds between two Dates in JavaScript?
- How to get the number of days between two Dates in JavaScript?

Advertisements