Blogger Information
Blog 29
fans 0
comment 0
visits 18380
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js变量,数据基础
CC
Original
486 people have browsed it

js基本介绍

  • 变量(区分大小写)

    变量初始化

    1. var x =3;
    2. console.log(X)

    声明变量,变量赋值

    1. // 声明变量
    2. var x;
    3. // 变量赋值
    4. x = 3;
    5. console.log(x)

    const 建议使用

    1. const x =3
    2. console.log(x)

    var初始化,可以重新赋值

    1. var x =3;
    2. x=5;
    3. console.log(x)
  • 变量类型

    基本的数据类型
    Number String Boolean undefined null
    引用的数据类型
    Object Array Function
    1.Number (数值类型)

    1. const a =4;
    2. const b = 1.234;
    3. const c =-1;
    4. console.log(typeof a);
    5. console.log(typeof b);
    6. console.log(typeof c);

    字符拼接

    1. const a = '3';
    2. const b ='5'
    3. const c = a+b
    4. console.log(c);

    2.string,使用双引号或是单引号 (字符串)

    1. const a ='chw';
    2. const b = "1.234";
    3. const c ='-1';
    4. console.log(typeof a);
    5. console.log(typeof b);
    6. console.log(typeof c);

    3.boolean 0(假 false) 和1(真 true)

    1. var c = 3 <= 4;
    2. alert(c);
    3. alert(typeof c);

    4.undefined

    1. var x;
    2. console.log(x)

    5.数组(支持下标索引取值)

    1. const a = ['3',"chen",4,5];
    2. console.log(a[1])

    二维数组

    1. const a = ['3',"chen",[4,5]];
    2. console.log(a)

    contst可以增删改

    1. const chw = [1, 2, 3]
    2. chw[1]=5
    3. console.log(chw)

对象

  1. let user={
  2. id:1,
  3. name:"chen",
  4. tell:"18111",
  5. "printtt":function(){
  6. console.log('我的姓',this.name);
  7. }
  8. }
  9. console.log(user.id,user.name,user['printtt'])
  • js运算符
    1. const a = 3;
    2. const b = 4;
    3. const c = a + b;
    4. const d = a * b;
    5. const e = 3 - 4;
    6. const f =c+3;
    7. console.log(c);
    8. console.log(d);
    9. console.log(e+3*c);
    10. console.log(f);
    使用contst,不存在a++等于a=a+1,c=a+5等于c+=5
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