What characters are valid for JavaScript variable names?

后端 未结 12 1946
情深已故
情深已故 2020-11-21 04:26

Which characters can be used for naming a JavaScript variable?

I want to create a small \"extension library\" for my non-JavaScript users here at work (who all seem

12条回答
  •  自闭症患者
    2020-11-21 04:52

    Javascript Variables

    You can start a variable with any letter, $, or _ character. As long as it doesn't start with a number, you can include numbers as well.

    Start: [a-z], $, _

    Contain: [a-z], [0-9], $, _

    jQuery

    You can use _ for your library so that it will stand side-by-side with jQuery. However, there is a configuration you can set so that jQuery will not use $. It will instead use jQuery. To do this, simply set:

    jQuery.noConflict();
    

    This page explains how to do this.

提交回复
热议问题