Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // const person = {
- // firstName: 'samim',
- // lastName: 'fazlu',
- // age: 30,
- // fullName() {
- // return this.firstName + '-' + this.lastName + '-' + this.age
- // },
- // }
- //pulling out of property from object or array
- // const { firstName, fullName, ...restValues } = person
- // console.log(fullName)
- // // console.log(fullName.call(person))
- // // console.log(myAge)
- // console.log(restValues)
- // const arr = ['samim', 'Fazlu', 30]
- // // const [fName, , age] = arr
- // const [fName,... restArr] = arr
- // console.log(arr[0])
- // console.log(restArr)
- // console.log(fName, age)
- // console.log(person.firstName)
- // console.log(person.lastName)
- // console.log(person.age)
- // console.log(person.fullName)
- //rest (...) Destructuring
- //spread(...)
- // const personWithProfession = {
- // ...person,
- // profession: 'App Developer',
- // }
- // console.log(personWithProfession)
- // const newWdArr = [...arr, 'web developer']
- // console.log(newWdArr)
- // function printPerson(fName, lName, age) {
- // }
- // const person = {
- // firstName: 'samim',
- // lastName: 'fazlu',
- // age: 30,
- // }
- // printPerson('samim', "hasan")
- //scope (the world where data is defined and can be accessed)
- //var (functional scope, global scope)
- //let, const(block scope {}, global scope)
- //if variable is declared globally with var or let or const keyword it can be accessed any part of the script
- // var a = 10
- // function b() {
- // var c = 20
- // // console.log(a)
- // console.log(c)
- // return c
- // }
- // b()
- // b()
- // console.log(a)
- // // console.log(c)
- //if let ,const is declared inside block{} then it will be available only in inside the block{}
- //otherwise it will be considered as global(global variable can be accessed from anywhere)
- //loop gotcha
- // const d = 40
- // {
- // var e = 50
- // const blockVar = 30
- // console.log(blockVar)
- // // console.log(d)
- // }
- // console.log(e)
- // console.log(blockVar)
- // for (let i = 0; i < 10; i++) {
- // console.log(i)
- // }
- // console.log(i)
- //scope chain
- // From children scope you can access parent scoped variable (children can access parent property) -scope chain
- // const a = 20
- // function showScope() {
- // const a = 10
- // {
- // const a = 100
- // console.log(a)
- // const b = 20
- // console.log(b)
- // }
- // console.log(a)
- // console.log(b)
- // }
- // showScope()
- //closure scope
- //variable scope is limited to it's function lifespan
- //After function execution is over(function running) it's scoped variable is vanished except the variable reference from inner function
- // function sum(num1) {
- // num1 = 3
- // return (num2) => {
- // return num1 + num2
- // }
- // }
- // const innerFunc = sum(3)
- // console.log(innerFunc(4))
- //Hoisting (lifting up variable and accessing in different part)
- // console.log(a)
- // console.log(func())
- // console.log(hello())
- // const a = 10
- // const func = function () {
- // console.log('Hi')
- // }
- // console.log(func())
- // function hello() {
- // return 'hello'
- // }
- //preparation phase
- //function declaration (statement) in memory
- //variable declaration (memory)
- //variable value is not set
- // var a;
- //var func
- //function hello(){
- // return 'hello'
- // }
- //execution phase
- // variable value assign
- //calling..
- // console.log(a) //undefined
- // console.log(func())
- // console.log(hello()) //'hello'
- //a = 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement