Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //accessing data from nested array and object
- //copy by value vs copy be reference, pass by by value vs pass by reference
- //constructor vs factory function
- //Evolution of function
- //nested loop
- // const arr = [
- // 'a',
- // 'b',
- // 'c',
- // 'd',
- // ['e', 'f', ['g']],
- // function () {
- // return 'Hi'
- // },
- // 'h',
- // 'i',
- // ]
- // //accessing data by index
- // console.log(arr[0])
- // console.log(arr[4][1])
- // console.log(arr[4][2][0])
- // console.log(arr[4][2][0])
- // console.log(arr[5]())
- //array vs object
- //accessing data from object
- // const obj = {
- // a: "b",
- // c: {
- // d: "e",
- // f: {
- // g: "h"
- // }
- // },
- // i: function(){
- // return obj.a //b
- // }
- // }
- // console.log(obj.c.d)
- // console.log(obj.c.f.g)
- // console.log(obj.i())
- //primitive data (string, number.....)
- //complex data type or object (array, object, function)
- //copy by value (primitive)
- // let a = 10
- // const b = a
- // a = 20
- // console.log(a, b)
- // //copy by reference (object) (value is in in specific location)
- // let aObj = {
- // value: {
- // a : 1
- // }
- // }
- // const bObj = JSON.parse(JSON.stringify(aObj))
- // aObj.value.a = 2
- // console.log(aObj, bObj)
- //pass by value (primitive)
- // function printByValue(a){
- // let b = a
- // a = 20
- // console.log(a)
- // console.log(b)
- // }
- // const a = 10
- // printByValue(a)
- //pass by reference (object type)
- // function printByRef(aObj){
- // let bObj = aObj
- // aObj.value = 20
- // console.log(aObj)
- // console.log(bObj)
- // }
- // const aObj = {
- // value: 10
- // }
- // printByRef(aObj)
- // console.log(aObj)
- //Evolution of function
- //function statement(? command)
- // function sum(a, b){
- // return a + b
- // }
- //function expression(? value)
- //10 , 20 , true, false
- //expression can be written on right side of variable
- // const sum = function(a, b){
- // return a + b
- // }
- //arrow function
- // const sum = (a, b) => {
- // return a + b
- // }
- // const sum = (a, b) => a + b
- // 2 ^ 4 = 2 *2 *2 *2
- // const exponential = a => a ** 2
- // console.log(exponential(10))
- //constructor function vs factory function
- // const user = {
- // firstName: 'samim',
- // lastName: 'Hasan',
- // age: 30,
- // fullName() {
- // return this.firstName + this.lastName
- // },
- // }
- //factory function
- // function createUser(firstName, lastName, age) {
- // return {
- // firstName,
- // lastName,
- // age,
- // fullName() {
- // return this.firstName + ' ' + this.lastName
- // },
- // }
- // }
- // const samim = createUser('samim', 'Hasan', 30)
- // const shanto = createUser('shanto', 'khan', 23)
- // console.log(shanto)
- // console.log(shanto.fullName())
- // console.log(samim.fullName())
- //constructor function
- // function User(firstName, lastName, age) {
- // //{} == this
- // this.firstName = firstName
- // this.lastName = lastName
- // this.age = age
- // this.fullName = function(){
- // return this.firstName + ' ' + this.lastName
- // }
- // //return this
- // }
- // const samim = new User('samim', 'Hasan', 30)
- // const shanto = new User('shanto', 'khan', 23)
- // console.log(samim.fullName())
- // console.log(shanto.fullName())
- //nested loop (primer)
- // for(let i = 0; i < 3; i++){
- // console.log(i)
- // for(let j = 0; j < 3; j++){
- // console.log(i, j)
- // }
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement