JavaScript variables and constants

1. What is a constant?

Constant represent some fixed data

Sex reality of human life can be seen as a constant fact, I was born a boy for life are boys, girls, life is born girl

Category 2.JavaScript in constant

2.1 integer constant

Integer constant is actually a positive number, just write an integer in JavaScript are integer constant
1/666/99

2.2 real constant

Real constant is actually a decimal in JavaScript just write a decimal are real constants
3.14 6.66

String constants 2.3

In fact, string constants is to use single quotation marks or double quotation marks content, we call it a string constant
'a', 'abc', "1", " I love you China"

Precautions: Whether enclosed in single or double quotes up how many characters are string constants in JavaScript

2.4 Boolean constants

Boolean constants in fact, true or false, expressed through true and false in JavaScript
only two values in JavaScript Boolean constants, True (true) or false (false)

 

3. What is a variable

Variable represents some of the data may change. When the value of a data requires frequent changes or are not sure, they should be represented by a variable

For example: the storage compartment is equivalent to a supermarket variable, which can store a variety of different things, things which are often stored may change

3.1 How to define a variable

In JavaScript can be generated by defining a variable manner compartments, that is, to tell the browser, we need a memory space
var + variable names;

let + variable names;

3.2 How to use variables

Using variables is that memory space to store data applications, and access to stored data

3.3 How to store data

Variable name = data to be stored;
data may need to store the right hand side of the equal sign variable on the left into the application memory space of the piece

3.4 How to get the data stored in the variable

Variable name
// define a variable
var NUM;
// store data to the variable
NUM = 123;
// get the data from the stored variable
console.log (num);

Guess you like

Origin www.cnblogs.com/sunchao0709/p/11707078.html