How to get the difference between two numbers in JavaScript

1 Answer

0 votes
function getDifference(a, b) {
  	return Math.abs(a - b);
}

console.log(getDifference(12, 18));
console.log(getDifference(4, 9)); 
console.log(getDifference(-3, 8));
console.log(getDifference(-2, -6));

  
  
  
  
/*
run:
  
6
5
11
4
  
*/

 



answered May 25, 2022 by avibootz
...