版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/enjoy_sun_moon/article/details/88885021
let const 都不能重复声明
let 是变量 可以重复赋值
const常量 不可以重复赋值
let,const 是块级作用域 比如 { } if() {} for () {}
var 是函数级别的作用域
<script type="text/javascript">
console.log(a); // undefined
var a = 20;
// ES6
// console.log(a); // a is not defined
// let a = 20;
var person = {
name: 'tom',
getName: function() {
return this.name;
}
}
var a = person.getName()
console.log(a) //tom
const persons = {
name: 'tom',
getName: () => this.name
}
var b = persons.getName()
console.log(b) // 空
if(true) {
var c = 'jeene'
}
console.log(c) // jeene
if(true) {
let d = 'john'
}
console.log(d) // d is not defined
function test(a,b,...args) {
alert(a)
alert
}
test(1,2,3,4,5)
</script>
数组声明新特性 let {a,b,c} = {a:12,b:3,c:23}
js字符串新函数
str.startsWith('str') 以str为开始
str.endsWith('str') 以str为结束
var str = 'dfassdf32323.jpg'
fres = str.startsWith('dfa')
eres = str.endsWith(".jpg")
console.log(fres) //true
console.log(eres) //true
模板字符串:
1.使用反单引号扩住 直接把变量塞到字符串里 使用${var}
新旧面向对象编程对比
新
旧