+ 5
I would like to know how I turn a string into an integer in JavaScript.
I'm coding a game with web languages, but I need to track the score and hits dealt.
6 Respostas
+ 8
Hi Michele Rene Machado ! You can use the parseInt() function. parseInt("12") would become the integer 12.
+ 4
Oh, okay, thank you, I wasn't aware of the function.
+ 4
You're most welcome! Have fun building your game! 😊
+ 2
Michele Rene Machado the asker can mark best answer (the tick below upvote/downvote)
+ 2
A quicker method is to simply multiply it by one.
"12"*1 === 12
0
This can also be achieved using the Number() method however parseInt() is preferred