当前位置:网站首页>JS day 2 (variables, variable usage, naming rules, syntax extensions)
JS day 2 (variables, variable usage, naming rules, syntax extensions)
2022-07-27 04:40:00 【Pillow said he didn't want to wake up】
One 、 What is a variable
It's a box of things , Variables are data containers for storing , Refers to a section of memory space in a computer , We get data by variable name , Even the data can be modified
The essence : A variable is a piece of space requested by the program in memory for storing data
Two 、 Use of variables
Variables are used in two steps :
1、 Declare variables Open up memory space
var age;// Declare variables :2、 assignment Store data in memory space
age = 18;
3、 Output results
console.log(age);4、 Initialization of a variable : Declare a variable and assign a value , We call it initialization of variables
//1、 Make a statement age The variable of
var age;
//2、 assignment , Store values in variables
age = 18;
//3、 Output results
// console.log(age);
//4、 Initialization of a variable
var myname = ' Pillow can't wake up ';
console.log(myname);
// The variable is declared with a value of 18
// Declare a variable and assign a value , We call it initialization of variables 3、 ... and 、 Naming rules for variables
1、 Variable names can be given by Numbers Letter Underline Element composition
2、 Cannot start with a number
3、 You can't use keywords and reserved words var for if class
4、 To see the meaning of name
5、 Hump named : Hump The first letter of every word should be capitalized Student Name
Little hump First word lowercase , The rest of the words start with single shoes student Name
Four 、 Syntax extension of variables
1、 Update variables : After a variable has been reassigned , Its original value will be overwritten , The value of the variable will be based on the last assigned value
Code display :
<script>
//1、 Update variables
var myname = ' teacher ';
console.log(myname);
myname = ' Pillow can't wake up ';
console.log(myname);
</script>Result display :

2、 When multiple variables are declared , Just write one var, Multiple variable names are separated by commas
// When multiple variables are declared , Just write one var, Multiple variable names are separated by commas
// var age = 18
// var address = ' Naruto ';
// var gz = 2000;
var age = 18,
address = ' Naruto '
gz = '2000'3、 Special cases of declaring variables
(1) Only declare , No assignment , The result is undefined Undefined
Code display :
var sex;
console.log(sex);Pictures show :
![]()
(2) Neither declaration nor assignment , Using a variable directly will definitely report an error
Code display :
console.log(tel); Pictures show :
(3) Do not declare direct assignment to use , Can get results , But not recommended
Code display :
qq = 110;
console.log(qq)Pictures show :

The best way to write : Declare variables and assign values
边栏推荐
- Effect Hook
- Interview must ask | what stages does a thread go through from creation to extinction?
- Pinia uses plug-ins for persistent storage.
- Spark practice case (upgraded version)
- Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
- Unity:Resource Merging、Static Batching、Dynamic Batching、GPU Instancing
- Shell programming enhancements
- Pinia uses the whole process, including state, actions, getters, and how to deconstruct, respond, and various methods used by actions
- 微信小程序编辑头像
- Understand kingbasees V9 in one picture
猜你喜欢

Okaleido ecological core equity Oka, all in fusion mining mode

【独立站建设】跨境电商出海开网店,首选这个网站建设!

F - Pre-order and In-order(Atcoder 255)

Do you know about wechat merchant billing?
![[day02] Introduction to data type conversion, operators and methods](/img/81/e2c49a4206e5d0d05308a1fc881626.png)
[day02] Introduction to data type conversion, operators and methods

Use unity to build a WordArt system

Deep analysis - dynamic memory management

佳明手表怎么设置用户定制显示

Yolov4 network details

Brightcove appoints Dan Freund as chief revenue Officer
随机推荐
从零开始C语言精讲篇4:数组
Dry goods | how can independent station operation improve online chat customer service?
Pinia uses the whole process, including state, actions, getters, and how to deconstruct, respond, and various methods used by actions
【HCIP】重发布、重分布、重分发实验
els 兼容性DC、传递图片到窗口
How to set user-defined display for Jiaming Watch
Shel automatically sets directory permissions
Sed output specified line
深度学习领域图像分割FCN(Fully Convolutional Networks for Semantic Segmentation)
JMeter learning notes 004-csv file line number control cycle times
Title: there is an array that has been sorted in ascending order. Now enter a number and ask to insert it into the array according to the original rule.
负数的右移
Explain left value, right value, left value reference and right value reference in detail
好用移动APP自动化测试框架哪里找?收藏这份清单就好了!
Yolov4网络详解
Ref Hook
RSA 非对称 加密解密 加签验签工具
Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)
The data in echart histogram is displayed at the top of the chart
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!