Last updated on Dec 15, 2022 by Suraj Sharma
let x = 25; x = -x;
We can convert a string to a number with a negative sign using the
parseFloat() function and then use the negation operator to change its sign.
let str = "5"; let x = -parseInt(str); // -5 let y = -parseFloat('2.23'); // -2.23
Rate this post
Suraj Sharma is a Full Stack Software Engineer. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.