JavaScript all loop and object and ternary operator

 Defining Class

 
    class Person {
        constructor(firstName, lastName) {
        console.log(this) // Check the output from here
        this.firstName = firstName
        this.lastName = lastName
        }
    }
 

 Ternary Operator

 
    let isRaining = true
    isRaining
    ? console.log('You need a rain coat.')
    : console.log('No need for a rain coat.')
 

 

 We declare object literal with const.


    // declaring object literal
    const person = {
        firstName: 'Asabeneh',
        lastName: 'Yetayeh',
        age: 250,
        country: 'Finland',
        city: 'Helsinki',
        skills: ['HTML','CSS','JavaScript','TypeScript', 'React','Node','MongoDB','Python','D3.js'],
        isMarried: true
    }
    // iterating through object keys
    for(const key in person) {
        console.log(key, person[key])
    }
 

 

 

 

JavaScript Loop




    for (let i = 0; i < n; i++){
        console.log()
    }

    // declaring an array variable
    const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']

    // iterating an array using regular for loop
    let len = names.length;
    for(let i = 0; i < len; i++){
        console.log(names[i].toUpperCase())
    }


    // iterating an array using for of
    for( const name of names) {
        console.log(name.toUpperCase())
    }

    // iterating array using forEach
    names.forEach((name) => name.toUpperCase())


    const person = {
    firstName: 'Asabeneh',
    lastName: 'Yetayeh',
    age: 250,
    country: 'Finland',
    city: 'Helsinki',
    skills: ['HTML','CSS','JavaScript','React','Node','MongoDB','Python','D3.js'],
    isMarried: true
    }
    for(const key in person) {
        console.log(key)
    }

إرسال تعليق (0)
أحدث أقدم