标签:anim 函数 syntax hello prot const not red tor
function sayHi() { console.log(name) console.log(age) var name = ‘Lydia‘ let age = 21 } sayHi()
Lydia
和 undefined
Lydia
和 ReferenceError
ReferenceError
和 21
undefined
和 ReferenceError
for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1) } for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1) }
0 1 2
和 0 1 2
0 1 2
和 3 3 3
3 3 3
和 0 1 2
const shape = { radius: 10, diameter() { return this.radius * 2 }, perimeter: () => 2 * Math.PI * this.radius } shape.diameter() shape.perimeter()
+true; !"Lydia";
const bird = { size: ‘small‘ } const mouse = { name: ‘Mickey‘, small: true }
let c = { greeting: ‘Hey!‘ } let d d = c c.greeting = ‘Hello‘ console.log(d.greeting)
let a = 3 let b = new Number(3) let c = 3 console.log(a == b) console.log(a === b) console.log(b === c)
class Chameleon { static colorChange(newColor) { this.newColor = newColor return this.newColor } constructor({ newColor = ‘green‘ } = {}) { this.newColor = newColor } } const freddie = new Chameleon({ newColor: ‘purple‘ }) freddie.colorChange(‘orange‘)
let greeting greetign = {} // Typo! console.log(greetign)
function bark() {
console.log(‘Woof!‘)
}
bark.animal = ‘dog‘
function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } const member = new Person("Lydia", "Hallie"); Person.getFullName = function () { return `${this.firstName} ${this.lastName}`; } console.log(member.getFullName());
function Person(firstName, lastName) { this.firstName = firstName this.lastName = lastName } const lydia = new Person(‘Lydia‘, ‘Hallie‘) const sarah = Person(‘Sarah‘, ‘Smith‘) console.log(lydia) console.log(sarah)
function sum(a, b) { return a + b } sum(1, ‘2‘)
let number = 0 console.log(number++) console.log(++number) console.log(number)
function getPersonInfo(one, two, three) {
console.log(one)
console.log(two)
console.log(three)
}
const person = ‘Lydia‘
const age = 21
getPersonInfo`${person} is ${age} years old`
function checkAge(data) { if (data === { age: 18 }) { console.log(‘You are an adult!‘) } else if (data == { age: 18 }) { console.log(‘You are still an adult.‘) } else { console.log(`Hmm.. You don‘t have an age I guess`) } } checkAge({ age: 18 })
function getAge(...args) { console.log(typeof args) } getAge(21)
function getAge() { ‘use strict‘ age = 21 console.log(age) } getAge()
const sum = eval(‘10*10+5‘)
sessionStorage.setItem(‘cool_secret‘, 123)
var num = 8 var num = 10 console.log(num)
const obj = { 1: ‘a‘, 2: ‘b‘, 3: ‘c‘ } const set = new Set([1, 2, 3, 4, 5]) obj.hasOwnProperty(‘1‘) obj.hasOwnProperty(1) set.has(‘1‘) set.has(1)
const obj = { a: ‘one‘, b: ‘two‘, a: ‘three‘ }
console.log(obj)
for (let i = 1; i < 5; i++) { if (i === 3) continue console.log(i) }
String.prototype.giveLydiaPizza = () => { return ‘Just give Lydia pizza already!‘ } const name = ‘Lydia‘ name.giveLydiaPizza()
const a = {} const b = { key: ‘b‘ } const c = { key: ‘c‘ } a[b] = 123 a[c] = 456 console.log(a[b])
const foo = () => console.log(‘First‘) const bar = () => setTimeout(() => console.log(‘Second‘)) const baz = () => console.log(‘Third‘) bar() foo() baz()
<div onclick="console.log(‘first div‘)"> <div onclick="console.log(‘second div‘)"> <button onclick="console.log(‘button‘)"> Click! </button> </div> </div>
<div onclick="console.log(‘div‘)"> <p onclick="console.log(‘p‘)"> Click here! </p> </div>
const person = { name: ‘Lydia‘ } function sayHi(age) { console.log(`${this.name} is ${age}`) } sayHi.call(person, 21) sayHi.bind(person, 21)
function sayHi() { return (() => 0)() } typeof sayHi()
0 new Number(0) (‘‘) (‘ ‘) new Boolean(false) undefined
console.log(typeof typeof 1)
const numbers = [1, 2, 3] numbers[10] = 11 console.log(numbers)
(() => { let x, y try { throw new Error() } catch (x) { (x = 1), (y = 2) console.log(x) } console.log(x) console.log(y) })()
[[0, 1], [2, 3]].reduce( (acc, cur) => { return acc.concat(cur) }, [1, 2] )
!!null
!!‘‘
!!1
setInterval(() => console.log(‘Hi‘), 1000)
[...‘Lydia‘]
function* generator(i) { yield i; yield i * 2; } const gen = generator(10); console.log(gen.next().value); console.log(gen.next().value);
const firstPromise = new Promise((res, rej) => { setTimeout(res, 500, "one"); }); const secondPromise = new Promise((res, rej) => { setTimeout(res, 100, "two"); }); Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
let person = { name: "Lydia" }; const members = [person]; person = null; console.log(members);
const person = { name: "Lydia", age: 21 }; for (const item in person) { console.log(item); }
console.log(3 + 4 + "5");
const num = parseInt("7*6", 10);
[1, 2, 3].map(num => { if (typeof num === "number") return; return num * 2; });
标签:anim 函数 syntax hello prot const not red tor
原文地址:https://www.cnblogs.com/jjgw/p/12173488.html