Is there a command (or symbol) that makes the math module a value?
For example: var teste = |10|-|6|;
Is there a command (or symbol) that makes the math module a value?
For example: var teste = |10|-|6|;
This |n|
syntax does not exist in JavaScript, at least for this purpose.
What you should do is use Math.abs()
. Examples:
var teste = Math.abs(10)-Math.abs(6); // 4
var teste = Math.abs(10-6); // 4
var teste = Math.abs(-10-6); // 16
var teste = Math.abs(-10-(-6)) // 4
Note: When involving mathematical operations between values, use
Math.abs()
for each value. For example:
Math.abs(10) - Math.abs(-6)
is different fromMath.abs(10-(-6))
. O first returns4
and second16
.
From what I understand you want the representation in module of a number. See Math.abs()
console.log(Math.abs(10));
console.log(Math.abs(-10));