注釋不會(huì)被解釋執(zhí)行,注釋被用來(lái)將代碼解釋給其他程序員看,或者是為了對(duì)代碼作用的簡(jiǎn)單描述。因此提高代碼的可讀性。
在Javascript中,可以使用兩種方式進(jìn)行注釋:
//:// 這是注釋?zhuān)瑢⒈唤忉屍骱雎?var a = "this is a variable defined in a statement";
/*開(kāi)始,用*/結(jié)尾:/*
這是多行注釋?zhuān)?將被解釋器忽略
*/
var a = "this is a variable defined in a statement";
將作者的話變成注釋
Mark me as a comment
or I'll throw an error
/*
Mark me as a comment
or I'll throw an error
*/
assert(true);