How to use unary negation (-) operator in JavaScript

1 Answer

0 votes
const x = 5;
const y = -x;

console.log(y);

const a = '7';
const b = -a;

console.log(b);

 
  
 
/*
run:
 
-5
-7
 
*/

 



answered Nov 18, 2020 by avibootz

Related questions

1 answer 172 views
1 answer 177 views
1 answer 159 views
1 answer 208 views
1 answer 189 views
1 answer 226 views
1 answer 157 views
157 views asked Jan 9, 2016 by avibootz
...