JavaScript beginner troubles with quotation marks

前端 未结 2 1515
长发绾君心
长发绾君心 2021-01-28 19:33

I\'m trying to learn JS from a book (Beginner JavaScript by Jeremy McPeak), but I\'m stuck with this code:



        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 20:06

    myString is a string. The function parseInt(string, radix) will parse a string as a integer (see this for more examples).

    The quotes are the way they are so that the output has the quotes displayed. If you don't want the quotes in the output the js could be simplified to:

    document.write(myString + " is " + parseInt(myString, 10) + " as an integer" + "
    ");

    but this wouldn't be as clear in showing how parseInt works.

提交回复
热议问题