+ 1
Why are answers from variable prompts strings in JavaScript no matter what I enter
Every time I enter a specific number, the outputs are shown as strings, as the same type as inputing some text. Why does it works in such way?
3 Réponses
+ 5
As mentioned already, prompt returns a string of text you entered.
Aside from eval(), you can also use Number() and parseInt() for integers and parseFloat() for floating point numbers.
https://code.sololearn.com/W748XyDSiKdd/?ref=app
+ 3
I think its because the prompt method is of type String
+ 1
because prompet function return a string value..
but you can use (eval)
such:
x=eval(prompt("x=","0"));