Fiald case 1: let can work in it's block

{
let a = 10;
var b = 1;
} a // ReferenceError: a is not defined.
b //

Case 2: Let has no "Hosting" Problem

function do_something() {
console.log(foo); // ReferenceError
let foo = 2;
}
function do_something() {
console.log(foo); //undefined
var foo = 2;
} //hosting:
function do_something() {
var foo = undefined;
console.log(foo);
foo = 2;
}

Case 3: let不允许在相同作用域内,重复声明同一个变量: In a block, you can only define one variable one time.

// 报错
{
let a = 10;
var a = 1;
} // 报错
{
let a = 10;
let a = 1;
}

But if you do something like:

function f1() {
let n = 5;
if (true) {
let n = 10;
}
console.log(n); //
}

There is no problem! becuase 5 and 10 are in different block scope.

[ES6] 04. The let keyword -- 2 Fiald case的更多相关文章

  1. [ES6] 03. The let keyword -- 1

    var message = "Hi"; { var message = "Bye"; } console.log(message); //Bye The mes ...

  2. [ES6] 05. The leg keyword -- 3. Block Scope

    In ES6, IIFE is not necessary: // IIFE写法 (function () { var tmp = ...; ... }()); // 块级作用域写法 { let tm ...

  3. ES6 Syntax and Feature Overview

    View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reass ...

  4. ES6中的数组

    数组是js中很重要的数据类型,虽然在 ES5 中,关于数组的方法和属性很多.但为了更加简洁.高效的操作数组,ES6 中又在数组原型上和实例上新增了一些方法. 一.Array方法 1.1 Array.f ...

  5. Java 8 Features – The ULTIMATE Guide--reference

    Now, it is time to gather all the major Java 8 features under one reference post for your reading pl ...

  6. c# ref 的作用

    Usage of ref keyword in C#  When we pass a value type variable as a parameter, then it passes its va ...

  7. 2小时入门Robot Framework

    1.介绍 1.1.介绍Robot Robot Framework是一个基于关键字驱动的自动化测试框架.通过该框架,测试人员可使用python封装关键字,并在非代码环境下使用关键字构建可被执行的测试用例 ...

  8. PHP安全编程:过滤用户输入

    如果你能正确可靠地识别和过滤输入,你的工作就基本完成了.最后一步是使用一个命名约定或其它可以帮助你正确和可靠地区分已过滤和被污染数据的方 法.我推荐一个比较简单的命名约定,因为它可以同时用在面向过程和 ...

  9. ArcGIS API for Silverlight 调用GP服务加载等值线图层

    原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层 第二篇.Silverlight客户端调用GP服务 利用ArcGIS API for Silverlight实现G ...

随机推荐

  1. Java反射机制demo(二)—通过Class实例化任意类的对象

    Java反射机制demo(二)—通过Class实例化任意类的对象 上一章节中,实例化了Class类对象的实例,这个部分的demo展示了如何使用Class对象的实例去获得其他类的对象的实例. 任意一个类 ...

  2. centos7.3挂在移动硬盘(亲测)

    一 下载ntfs-3g wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2016.2.22.tgz 二 解压并安装 1 检测是否安装gcc r ...

  3. FastReport.Net使用:[1]屏蔽打印对话框

    1.如何设置默认打印机 在FastReport设计界面找到File->Printer Setup菜单,运行该菜单显示“打印机设置”对话框.在打印机(Printer)列表中选择默认打印机,并勾上“ ...

  4. 【BZOJ 4596】 4596: [Shoi2016]黑暗前的幻想乡 (容斥原理+矩阵树定理)

    4596: [Shoi2016]黑暗前的幻想乡 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 324  Solved: 187 Description ...

  5. 谈HTTPS中间人攻击与证书校验(一)

    一.前言 随着安全的普及,https通信应用越发广泛,但是由于对https不熟悉导致开发人员频繁错误的使用https,例如最常见的是未校验https证书从而导致“中间人攻击”,并且由于修复方案也一直是 ...

  6. hdu 3435 图回路分割

    将一个无向图分成许多回路,回路点交集为空,点幷集为V.幷最小化回路边权和. #include <cstdio> #include <cstring> #include < ...

  7. hdu 3046 最小割

    每个栅栏其实就是一条边,修一些栅栏,使得狼不能抓到羊,其实就是求一个割,使得羊全在S中,狼全在T中. #include <cstdio> #include <cstring> ...

  8. kali 执行apt-get upgrade后,终端无法打开的解决办法

    今天在kali执行apt-get upgrade命令后,reboot启动,发现进入界面终端无法开启 一波百度,google发现大概应该是语言的配置问题,因为最开始安装kali的时候是选择中文,可能up ...

  9. tortoise git常用功能

    1.打tag TortoiseGit -> show log -> 选中版本 -> create tag at this version... TortoiseGit -> p ...

  10. Windows7 无法访问共享文件,域访问解决方法。

    1.开始——>运行——>gpedit.msc 打开[本地组策略编辑器] 2.计算机配置——>Windows设置——>安全设置——>本地策略——>安全选项——> ...