Casting to string in JavaScript

前端 未结 8 1739
轻奢々
轻奢々 2020-12-04 07:59

I found three ways to cast a variable to String in JavaScript.
I searched for those three options in the jQuery source code, and they are all in use

8条回答
  •  时光说笑
    2020-12-04 08:24

    According to this JSPerf test, they differ in speed. But unless you're going to use them in huge amounts, any of them should perform fine.

    For completeness: As asawyer already mentioned, you can also use the .toString() method.

提交回复
热议问题