- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Eric Pimpler Mark Lewin
- 386字
- 2021-07-02 15:48:54
Variables
Variables are a fundamental concept that you need to understand when working with any programming language. Variables are simply names that we use to associate with a data value. At a lower level, these variables are areas of space carved out in a computer's memory that store data.
You can think of a variable as a box that has a name and that contains some sort of data. When we initially create the variable it is empty until data is assigned. Basically, variables give us the ability to store and manipulate data. In the following figure, we create a variable called ssn. Initially this variable is empty but is then assigned a value of 450-63-3567. The data value assigned to a variable can be of various types including numbers, strings, Booleans, objects, and arrays:

In JavaScript, variables are declared with the var keyword. In general, the names that you assign to your variables are completely up to you. However, there are certain rules that you need to adhere to when creating a variable:
- Variable names can contain both text and numbers, but should never start with a number. Always start your variable name with a letter or underscore.
- Spaces are not permitted. If you want your variable name to include multiple words, use camel case notation. This convention requires using lower case for the first word, and capitalizing the first letter of subsequent words. For example: myVariableName .
- Special characters such as percentage signs and ampersands are not allowed within variable names. Underscores, however, are permitted and can appear anywhere within the variable name.
Other than that, you are free to create variable names as you wish but you should try to assign variable names that describe the data that the variable will be assigned. It is also perfectly legal to declare multiple variables with the same var keyword as seen in the following code example:
var i, j, k;
You can also combine variable declarations with data assignments, as seen in the following examples:
var i = 10;
var j = 20;
var k = 30;
You may have also noticed that each JavaScript statement ends with a semicolon. The semicolon indicates the end of a statement in JavaScript and should always be included. Missing semicolons are the cause of many JavaScript programming errors.
- Puppet 4 Essentials(Second Edition)
- Python數(shù)據(jù)可視化:基于Bokeh的可視化繪圖
- 編程卓越之道(卷3):軟件工程化
- Arduino開(kāi)發(fā)實(shí)戰(zhàn)指南:LabVIEW卷
- Architecting the Industrial Internet
- 零基礎(chǔ)學(xué)Python數(shù)據(jù)分析(升級(jí)版)
- C++20高級(jí)編程
- Visual Basic程序設(shè)計(jì)習(xí)題與上機(jī)實(shí)踐
- 愛(ài)上C語(yǔ)言:C KISS
- 從零學(xué)Java設(shè)計(jì)模式
- 程序員必會(huì)的40種算法
- DevOps 精要:業(yè)務(wù)視角
- HTML5 Canvas核心技術(shù):圖形、動(dòng)畫與游戲開(kāi)發(fā)
- 零基礎(chǔ)C語(yǔ)言學(xué)習(xí)筆記
- Android項(xiàng)目實(shí)戰(zhàn):博學(xué)谷