当前位置: 首页 > wzjs >正文

web浏览器是啥如何做好seo基础优化

web浏览器是啥,如何做好seo基础优化,做网站 绑定域名,宝鸡seo培训在 JavaScript 里,const 和 let 都是 ES6(ES2015)引入的用于声明变量的关键字,它们和之前的 var 关键字有所不同。下面为你详细介绍 const 和 let 的区别: 1. 块级作用域 const 和 let 都具备块级作用域,…

在 JavaScript 里,constlet 都是 ES6(ES2015)引入的用于声明变量的关键字,它们和之前的 var 关键字有所不同。下面为你详细介绍 constlet 的区别:

1. 块级作用域

constlet 都具备块级作用域,也就是说变量仅在声明它的块(如 if 语句、for 循环等)内部有效。而 var 是函数作用域。

// 使用 let 声明
if (true) {let blockScopedLet = 'This is a let variable';console.log(blockScopedLet); // 输出: This is a let variable
}
// console.log(blockScopedLet); // 报错: blockScopedLet is not defined// 使用 const 声明
if (true) {const blockScopedConst = 'This is a const variable';console.log(blockScopedConst); // 输出: This is a const variable
}
// console.log(blockScopedConst); // 报错: blockScopedConst is not defined// 使用 var 声明
if (true) {var functionScopedVar = 'This is a var variable';console.log(functionScopedVar); // 输出: This is a var variable
}
console.log(functionScopedVar); // 输出: This is a var variable

2. 变量重新赋值

const 声明的常量一旦被赋值,就不能再重新赋值。不过,如果 const 声明的是对象或者数组,其内部的属性或元素是可以修改的。而 let 声明的变量可以重新赋值。

// 使用 let 重新赋值
let letVariable = 'Initial value';
console.log(letVariable); // 输出: Initial value
letVariable = 'New value';
console.log(letVariable); // 输出: New value// 使用 const 重新赋值会报错
const constVariable = 'Initial value';
console.log(constVariable); // 输出: Initial value
// constVariable = 'New value'; // 报错: Assignment to constant variable// const 声明的对象可以修改内部属性
const person = {name: 'John',age: 30
};
console.log(person.name); // 输出: John
person.name = 'Jane';
console.log(person.name); // 输出: Jane

3. 变量提升

var 存在变量提升的现象,也就是说在变量声明之前就可以访问该变量,只不过值为 undefined。而 constlet 虽然也存在变量提升,但在声明之前访问会引发 ReferenceError,这一区域被称作暂时性死区(TDZ)。

// 使用 var
console.log(varVariable); // 输出: undefined
var varVariable = 'Value';// 使用 let
// console.log(letVariable); // 报错: Cannot access 'letVariable' before initialization
let letVariable = 'Value';// 使用 const
// console.log(constVariable); // 报错: Cannot access 'constVariable' before initialization
const constVariable = 'Value';

总结

  • 块级作用域constlet 拥有块级作用域,var 是函数作用域。
  • 重新赋值const 声明的常量不能重新赋值(对象和数组的内部属性或元素除外),let 声明的变量可以重新赋值。
  • 变量提升var 存在变量提升,constlet 存在暂时性死区,声明前访问会报错。

在实际编码时,建议优先使用 const,当需要重新赋值时再使用 let,尽量避免使用 var

http://www.dtcms.com/wzjs/280178.html

相关文章:

  • 网站空间管理系统考研比较厉害的培训机构
  • 中铁建设工程项目公示网站清远市发布
  • 学校校园网站 资源建设方案免费制作自己的网页
  • 制作商城网站模板什么是sem和seo
  • 绵阳政府网站建设上海网站建设公司排名
  • 体验营销企业网站seo公司
  • 免费asp政府网站短信营销平台
  • 大专毕业论文3000字免费知乎seo
  • 代做效果图网站好宣传软文案例
  • 学校网站的常规化建设站长工具端口查询
  • 公司新成立想要搭建网站怎么做百度seo高级优化
  • wordpress游客变注册用户seo1域名查询
  • 深圳小程序开发长春seo快速排名
  • 德化住房和城乡建设网站设计网站的公司
  • 上海市建设工程质监站网站如何推广微信公众号
  • 宝塔做网站写文的免费软件
  • 模拟网站效果百度新闻发布平台
  • 公司名称可以和网站域名不同吗百度人气榜排名
  • 中山市 有限公司网站建设google下载
  • 网站升级维护中 模板西安seo公司
  • 中文域名是什么南京seo排名收费
  • ecshop 修改网站域名竞价托管推广公司
  • 做网站公司的未来口碑营销成功案例
  • 网站版建设平台seo
  • 电商网站布局设计google推广有效果吗
  • 电子商务网站规划书五合一网站建设
  • 提供手机网站建设哪家好如何制作网页链接
  • 惠州网站建设外包宁波seo教学
  • 商城网站建设哪家专业广州网页搜索排名提升
  • 长春建设网站公司搭建自己的网站