使用驼峰名法:首字母小写,其他的有意义的单词大写(尽可能语义化) add/insert/create/new (新增) rm (删除) sel/select/query/get (查询) info (信息) 1. 2. 3. 4. 不能使用关键字和保留字 JS中常用的数据类型 基本数据类型 数字nubmer (常规数字/NaN) 字符串 string (所有单引号、双引号、反引号抱...
ES6 又新增了块级作用域,本教程不涉及。 函数外部声明的变量就是全局变量(global variable),它可以在函数内部读取。 varv =1;functionf() {console.log(v); } f()// 1 上面的代码表明,函数f内部可以读取全局变量v。 在函数内部定义的变量,外部无法读取,称为“...
The scope containing all of a program is calledglobal scopeorprogram scope.This is the scope you are in when entering a script (be it atag in a web page or be it a.jsfile). Inside the global scope, you can create a nested scope by defining a function. Inside such a function, you...
Now, for convenience, let’s create a reference to thewhoAmImethod, presumably so we can access it merely bywhoAmI()rather than the longerobj.whoAmI(): varwhoAmI = obj.whoAmI; And just to be sure we’ve stored a reference to a function, let’s print out the value of our newwhoAmIva...
Global variables defined with theletkeyword do not belong to the window object: Example letcarName ="Volvo"; // code here can not use window.carName Try it Yourself » Warning Do NOT create global variables unless you intend to. Your global variables (or functions) can overwrite window vari...
varname ="Jack";// local variable; only accessible in this showName function console.log (name);// Jack } console.log (name); // Richard: the global variable 没有块级作用域: varname ="Richard"; // the blocks in this if statement do not create a local context for the name variable...
When the JavaScript interpreter starts up, one of the first things it does, before executing any JavaScript code, is create aglobal object.The properties of this object are the global variables of JavaScript programs. When you declare a global JavaScript variable, what you are actually doing is...
DOCTYPE html>JavaScript debugging example//create a global variable for our vardisplay;functioninit(){//initialize only after the HTML has been loadeddisplay = document.getElementById("results"); }functionfirstParam(){//set breakpoint herevara =5; secondParam(a); }functionsecondParam(a){varb...
Toassigna value to the variable, use the equal sign: carName ="Volvo"; You can also assign a value to the variable when you declare it: letcarName ="Volvo"; In the example below, we create a variable calledcarNameand assign the value "Volvo" to it. ...
} // bad createUser( firstName, lastName, birthday ); // good createUser( firstName, lastName, birthday, ); ⬆ back to top Semicolons 21.1 Use semicolons. eslint: semi Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called Automatic Semi...