Blogger Information
Blog 13
fans 0
comment 0
visits 8361
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示js常用数据类型,变量与常量的声明与赋值
一米互联
Original
671 people have browsed it

JS —-> javaScript的简称

js中的常用数据类型:

1、数值类型:number

  1. let age = 50; 整数
  2. let num=3.1415926; 小数

2、字符串类型:string

  1. let name = apple;
  2. let emali = "zhangbeijing@163.com";

3、布尔类型:boolean

  1. let isMarr = true; /*或者false*/

4、未初始化类型:undeifned

  1. 未初始化变量的默认值
  2. let gender;
  3. console.log(gender); //undeifned

5、null对象:

  1. let pro = null;
  2. console.log(pro,typeof null); //返回的是object

6、符号,创建对象属性的唯一标识

  1. let s Symbol('custom symbol');
  2. console.log(s,typeof s);

7、使用typeof 检测数据类型

  1. console.log(age,typeof age);

8、字符串拼接使用”+“号

  1. console.log('邮箱' + email);

9、原始类型都是值传递

  1. let a = 100;
  2. // 将变量的a的值,传递到了b;
  3. let b = a;
  4. console.log(b);
  5. let a = 200;
  6. console.log(b);
  7. // a的更新不会影响到b

10、引用类型

10-1 对象字面量:

  1. let user = {
  2. // 属性,相当于变量
  3. id:1,
  4. name:'zhangzhongguo',
  5. 'my email':'123456@qq.con',
  6. // 方法:函数
  7. getName:function(){
  8. //this表示当前的上下文,当前对象
  9. return '我的名字叫:'+ this.name;
  10. }
  11. }
  12. console.log(user.id,user.name);
  13. console.log(user['my email']);
  14. console.log(user.getName());

10-2 数组:

  1. let course = [5,'javascript','php.cn'];
  2. //访问数组中的第二个值
  3. console.log(course[1]);

10-3 函数:

  1. function hello(){}
  2. console.log(hello,typeof hello);
  3. console.log(hello,instanceof Object);
  4. // 对象是属性的无序集合,对象可以添加属性
  5. hello.email = '123456@qq.com';
  6. console.log(hello.email);
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post