Giter Site home page Giter Site logo

es6_7study's Introduction

Hi. It's quoniammm

es6_7study's People

Contributors

quoniammm avatar

Watchers

 avatar  avatar

es6_7study's Issues

1.let和const命令

Image of EVA

//************eg1*************//
//===============执行结果为6=======================//
/*
'use strict'

var a = [];
for (let i = 0; i < 10; i++) {
  a[i] = function () {
    console.log(i);
  };
}
*/
//================执行结果为10====================//
/*
let i = 0;
while(i < 10){
    a[i] = function(){
        console.log(i);
    }
    i ++;
}
*/
//==============执行的语句:a[6]();=======================//

//************eg2*************//
/*
function f() { console.log('I am outside!'); }
(function () {
  if(false) {
    // 重复声明一次函数f
    function f() { console.log('I am inside!'); }
  }

  f();
}());
*/
//================ES5: I am inside! =================//
//================ES6: I am outside! ================//
//================执行的语句:f() ==================//

//let没有var所谓的‘变量提升’,let的作用域为代码块,代码块之外无法访问 <eg1>

//补充
/*
=1.暂时性死域
=2.不允许重复声明
=3.块级作用域,ES5的时候只有函数作用域,避免了内层变量可能会覆盖外层变量,用来计数的循环变量泄露为全局变量
=4.块级作用域的出现,实际上使得获得广泛应用的立即执行匿名函数(IIFE)不再必要了。
=5.ES6也规定,函数本身的作用域,在其所在的块级作用域之内。<eg2>
=6.const也用来声明变量,但是声明的是常量。一旦声明,常量的值就不能改变,作用域规则与let相同。
=7.对于复合类型的变量,变量名不指向数据,而是指向数据所在的地址。const命令只是保证变量名指向的地址不变,
并不保证该地址的数据不变,所以将一个对象声明为常量必须非常小心。
*/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.