I was going through a TypeScript code example and I noticed a special use of the "+" operator in the 3rd line of the code below:
let a: string = "12";
let b: number;
b = +a;
alert(`Result: ${b}`);
It works in TypeScript playground. If you remove the + operator in the 3rd line; you get a TypeScript error.
It seems that the + unary operator converts a string to a number.
I searched google and I am not able to trace any feature like that in neither JavaScript nor TypeScript. Perhaps I am not using the right keyword.
- What is the name of this feature or concept?
- Where is this documented?
- Is this a JavaScript or TypeScript feature?
Update
Thank you, everyone, for help. I am wondering if there is a similar feature for dates as well?