Skip to content

papaproger/fun-js-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

Fun JS Tasks

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]}`)

go to Contents

const a = {
    [Symbol.toPrimitive](hint) {
        return hint == "default" ? 1 : "2"
    }
}

//console.log(++a)

go to Contents

const a = {
    [Symbol.toPrimitive]() {
        return "javascript" === "JavaScript"
    }
}

//console.log(!a)

go to Contents

const a = {
    valueOf(hint) {
        return hint == "number" ? "1" : "2"
    }
}

//console.log(+a)

go to Contents

const a = {
    toString(hint = "default") {
        return hint == "default" ? 1 : 2
    }
}

//console.log(+a)

go to Contents

const str = "0xford University"

//console.log(parseInt(str))

go to Contents

//"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()

go to Contents

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++]()

go to Contents

//"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}`)

go to Contents

let s = 'closure'

function f() {
    console.log(s)
}

{
    let s = 'lexical scope'
    //f()
}

go to Contents

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

go to Contents

function F(x) {
    this.a = x
    this.inc = () => { this.a++ }
    //return { ...this }
}

obj = new F(1)
obj.inc()
//console.log(obj.a)

Pic-1

go to Contents

// "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();

go to Contents

// "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();

go to Contents

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)

go to Contents

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')

go to Contents

by

PapaProger

About

Fun JS Tasks - check your skills!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published