zoukankan      html  css  js  c++  java
  • 变量

    特点: 松散型类型

    结果:

    1. 仅仅是一个用来保存值得占位符,可随时变换类型;
    2. 未经过初始化得变量,默认值 undefined;
    3. var定义的变量 将是该变量得作用域的局部变量,如函数中var定义的变量,在函数退出后 就会被销毁
    4. 不使用操作符,直接定义一个变量,此变量将为一个全局变量。
    var msg = 123;
    console.log(typeof msg) // "number"
    msg = 'hello world';

    console.log(msg);// 'hello world'
    console.log(typeof msg)// "string"
    var msg; 
    console.log(msg === undefined) // true
    function hello() { var message = 'hello';}
     hello();
    console.log(message) // 报错:Uncaught ReferenceError: message is not defined
    
    function test() {
         a = '4545'; // 定义一个全局变量a, 严格模式下也ReferenceError
       b
    }
    console.log(a) // VM503:1 Uncaught ReferenceError: a is not defined
    console.log(b) // VM503:1 Uncaught ReferenceError: a is not defined
    test()

    console.log(a) // '4545'
    console.log(b) // VM503:1 Uncaught ReferenceError: a is not defined

      

  • 相关阅读:
    svn命令
    Lambda 表达式
    JAVA 探究NIO
    JAVA I/O系统
    MySQL 锁
    spring boot 集成 zookeeper 搭建微服务架构
    架构演化
    JAVA 集合
    spring boot 发送邮件
    MySQL 隔离级别
  • 原文地址:https://www.cnblogs.com/baixinL/p/13716809.html
Copyright © 2011-2022 走看看