Task #1 | Task #2 | Task #3 |
Task #4 | Task #5 | Task #6 |
Task #7 | Task #8 | Task #9 |
Task #10 | Task #11 | Task #12 |
Task #13 | Task #14 | Task #15 |
Task #16 |
const a = [1, 2, 3]
const b = {
0: 1,
1: 2,
2: 3,
}
const index = {
valueOf() {
return "1"
},
toString() {
return 2
},
}
//console.log(`${a[index]} ${b[index]}`)
const a = {
[Symbol.toPrimitive](hint) {
return hint == "default" ? 1 : "2"
}
}
//console.log(++a)
const a = {
[Symbol.toPrimitive]() {
return "javascript" === "JavaScript"
}
}
//console.log(!a)
const a = {
valueOf(hint) {
return hint == "number" ? "1" : "2"
}
}
//console.log(+a)
const a = {
toString(hint = "default") {
return hint == "default" ? 1 : 2
}
}
//console.log(+a)
const str = "0xford University"
//console.log(parseInt(str))
//"use strict"
var name = 'Masha'
var age = 35
let person = new function () {
this.name = 'Sveta'
this.age = 22
this.hello = function () { console.log(`Hello, ${this.name}!`) }
this.bye = () => { console.log(`Bye, ${this.name}!`) }
}
const user = {
name: 'Vova',
age: 32,
isAdmin: false,
happyBirthday: () => { console.log(`${this.name} is ${++this.age}.`) },
__proto__: person,
}
//user.hello()
//user.bye()
//user.happyBirthday()
var a = 1
function F(a) {
this.a = a
this.f1 = () => console.log(a)
this.f2 = () => console.log(this.a)
this.f3 = function () { console.log(this.a) }
return { ...this }
}
a = new F(10)
a.a++
//for (let i = 1; i <= 3;) a['f' + i++]()
//"use strict"
var a = 100
let obj1 = {
a: 1,
f() {
this.a++
(function () { this.a++ })() // (*)
},
}
obj1.f()
//console.log(`obj1.a = ${obj1.a}, a = ${a}`)
//"use strict"
var a = 100
let obj2 = {
a: 1,
f() {
this.a++
(() => { this.a++ })() // (*)
},
}
obj2.f()
//console.log(`obj2.a = ${obj2.a}, a = ${a}`)
let s = 'closure'
function f() {
console.log(s)
}
{
let s = 'lexical scope'
//f()
}
let a = 1
const f = () => {
console.log(`%c ${a} `, 'color: white; background: red')
}
a = 2
{
let a = 3
if (true) {
let a = 4
//f()
a = 5
}
a = 6
}
a = 7
function F(x) {
this.a = x
this.inc = () => { this.a++ }
//return { ...this }
}
obj = new F(1)
obj.inc()
//console.log(obj.a)
// "use strict"
var name = 'Emma'
const creature = {
hello() { console.log(`Hello, ${this.name || typeof this}!`) },
bye: () => { console.log(`Bye, ${this.name || typeof this}!`) },
}
const user = {
name: 'Alex',
__proto__: creature,
}
//creature.hello(); creature.bye();
//user.hello(); user.bye();
// "use strict"
var name = 'Emma'
class Creature {
constructor() {
this.hello = function () { console.log(`Hello, ${this.name || typeof this}!`) }
this.bye = () => { console.log(`Bye, ${this.name || typeof this}!`) }
}
}
const creature = new Creature()
class User extends Creature {
constructor(name = 'Noname') {
super()
this.name = name
}
}
const user = new User('Alex')
//creature.hello(); creature.bye();
//user.hello(); user.bye();
const theArray = [29053366, 902869993114]
const theKey = 0b100100
const theStyle = 'color: #FFFFFF; background: #800080; font-size: 30px; padding: 0 15px;'
const theFunction = () => theArray.map(i => i.toString(theKey)).join(' ').toUpperCase()
//console.log(`%c${theFunction()}`, theStyle)
const obj1 = {}
const obj2 = {}
const obj3 = {}
Object.defineProperty(obj1, 'prop', { value: 'Hello!' })
Object.defineProperty(obj2, 'prop', { value: 'Bye!' })
Object.defineProperty(obj3, '__proto__', { value: obj1 })
obj3.__proto__ = obj2
//console.log(obj3.__proto__.prop || 'No prop')
//console.log(obj3.prop || 'No prop')