4 ms·
You can convert to a number with a + before your variable. const y = +x + 12; Will be number addition even if x is a string.
by pleoxy 3y ago
You can convert to a number with a + before your variable.
const y = +x + 12;
Will be number addition even if x is a string.
- WorldMaker 3y agoOr via the Number constructor: const y = Number(x) + 12 Depending on your audience, that might be clearer in intent than `+x`.