console.log(null == undefined)
console.log(null === undefined)
console.log(typeof(new Object()) == typeof(null))
console.log(new Number('1') == 1)
console.log(new Number('1') === 1)
console.log(new Object('1') == 1)
console.log(new Object('1') === 1)
console.log(new Boolean() == false)
console.log(new Boolean() === true)
var a = 1
if (true) {
console.log(a)
var a = 2
var b = 3
console.log(b)
}
console.log(a)
console.log(b)
b = 4
var a = 1
function a () {}
console.log(a)
var a = 1
function fun(a, b) {
a = 2
arguments[0] = 3
arguments[1] = 1
return a + b
}
console.log(fun(0, 0))
console.log(a)
for (var i = 0; i < 5; i++) {
setTimeout(function() {
console.log(5)
}, 0)
}
console.log(6)
function A() {
this.num1 = 1
}
A.prototype.num2 = 2
function B() {
this.num1 = 3
}
B.prototype = new A()
var b1 = new B()
console.log(b1.num1)
console.log(b1.num2)
var b2 = B()
console.log(b2.num1)
console.log(b2.num2)
var a = {x: 1}
var b = a
a.x = a = {n: 1}
console.log(a)
console.log(b)
Function.prototype.a = () => alert(1)
Object.prototype.b = () => alert(2)
function A() {}
const a = new A()
a.a()
a.b()
let a = 0
console.log(a)
console.log(b)
let b = 0
console.log(c)
function c() {}
var x = 10
function a(y) {
var x = 20
return b(y)
}
function b(y) {
return x + y
}
console.log(a(20));
console.log(1)
setTimeout(() => {
console.log(2)
})
process.nextTick(() => {
console.log(3)
})
setImmediate(() => {
console.log(4)
})
new Promise(resolve => {
console.log(5)
resolve()
console.log(6)
})
.then(() => {
console.log(7)
})
Promise.resolve()
.then(() => {
console.log(8)
process.nextTick(() => {
console.log(9)
})
})
[1, 2, 3, 4, 5].map(parseInt) [1, NaN, NaN, NaN, NaN]
typeof typeof typeof []
<style>
div {color: red;}
#title {color: yellow;}
div.title {color: blue;}
</style>
<div class="title" id="title">abc</div>
<style>
.classA {color: blue;}
.classB {color: red}
</style>
<p class="classB classA">123</p>
function add(args) {
return args;
}
function one(fn) {
if(fn){
return 1 + fn;
}
return 1;
}
function two(fn) {
if(fn){
return 2 + fn;
}
return 2;
}
console.log(one(add(two())))
console.log(two(add(one())))
function A() {
this.name = name
}
A.prototype.name = 'xiaoming'
var a = new A()
console.log(a.name)
let a = 'ByteDance1'
let obj = {
a: 'ByteDance2',
fun1: function() {
console.log(this.a)
}
}
let fun2 = obj.fun1
fun2.call(null)
var name = '123'
function func() {
console.log(this.name)
}
var object = {
name: 'object',
getNameFunc: function(fn) {
fn && fn()
return function() {
return this.name
}
}
}
console.log(object.getNameFunc(func)())'object'
<style>
#a { font-size: 12px; }
div p { font-size: 13px; }
div .c { font-size: 14px; }
.a .b .c { font-size: 15px; }
#b { font-size: 16px }
<div id="b" class="b">
<p id="c" class="c">I'am here</p>
</div>
</style>
var obj = {a : { b: { c: 1 } }}
function find(obj, str){
const keys= str.split('.');
let current = obj;
for (var i = 0; i < keys.length; i++) {
if (!current.hasOwnProperty(keys[i])) {
return undefined;
}
current = current[keys[i]];
}
return current;
}
find(obj, 'a.b.c')
find(obj, 'a.d.c')
var a = 0, b = 0
function A(a) {
A = function (b) {
alert(a + b++)
}
alert(a++)
}
A(1)
A(2)
const list = [1, 2, 3];
const square = num => {
return new Promise(resolve => {
setTimeout(() => {
resolve(num * num);
}, 1000);
});
}
function test() {
list.forEach(async x => {
const res = await square(x);
console.log(res);
});
}
test()
<style>
.b { color: red;}
.a { color: blue;}
</style>
<div class="a b">Bytedance</div>
Object.prototype.toString.call([])
function A(){}
const a = new A();
console.log(a.constructor);
console.log(a.prototype);
a.abc = 123;
console.log(a.__proto__);
console.log(A.prototype.constructor);