Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //var, const let
- //function declaration, arrow function and single line return
- //template string/literal
- //conditional and logical AND(&&)
- //Array helper method(map, filter, find)
- // Destructuring, rest, spread
- // promise, async await
- // class
- //Let, var, const
- // var a = 10 //Don't use(to avoid some unexpected error, bug)
- // const b = 20
- // let c = 30
- // // b = 40 //error
- // c = 50
- // console.log(c)
- //function statement
- // function sum(num1, num2){
- // return num1 + num2
- // }
- //function expression
- // const sum = function (num1, num2) {
- // return num1 + num2
- // }
- //arrow function
- // const sum = (num1, num2) => {
- // return num1 + num2
- // }
- // const sum = (num1, num2) => num1 + num2
- // const multiply = (num) => num * 20
- // console.log(multiply(10))
- // const firstName = 'samim'
- // const lastName = 'Hasan'
- // const fullName = firstName + ' ' + lastName
- //javascript expression can be written inside in curly braces
- //statement - command (;) expression-value
- // const fullName = `My First Name is "${firstName.toUpperCase()}" and last name is "${lastName.toUpperCase()}".`
- // console.log(fullName)
- //conditional
- // const age = 20
- // if (age >= 18) {
- // console.log('You can vote')
- // } else {
- // console.log("You can't vote")
- // }
- //ternary
- // condition? true : false
- // const result = age >= 18 ? 'You can vote' : 'You can\'t vote'
- //logical and operator(&&)
- // const result = age >= 18 && 'You can vote'
- // const result = age >= 18 || 'You can vote'
- // console.log(result)
- // function double(nums) {
- // const dbl = []
- //imperative coding
- // for (let i = 0; i < nums.length; i++) {
- // dbl.push(nums[i] * 2)
- // }
- //declarative
- // for (let num of nums) {
- // dbl.push(num * 2)
- // }
- // return dbl
- //declarative
- // const result = nums.map((num) => num * 2)
- // return result
- // }
- // const nums = [1, 2, 3, 4]
- // console.log(double(nums))
- //[2, 4, 6, 8]
- //find
- // function findElm(recArr) {
- // return recArr.find((elm) => elm > 2)
- // }
- // const nums = [1, 2, 3, 4]
- // console.log(findElm(nums))
- //filter
- // function filterElms(recArr) {
- // return recArr.filter((elm) => elm > 2)
- // }
- // const nums = [1, 2, 3, 4]
- // console.log(filterElms(nums))
- //destructuring,
- // const person = {
- // firstName: 'samim',
- // lastName: 'Hasan',
- // age: 30,
- // }
- // const { firstName, age } = person
- // console.log(firstName)
- // console.log(age)
- // rest operator
- // const { firstName, ...restValues } = person
- // console.log(firstName)
- // console.log(restValues)
- // // spread operator
- // const newPersonObj = {
- // ...person,
- // profession: 'Programmer'
- // }
- // console.log(newPersonObj)
- // //array destrucring, rest, spread operator
- // const arr = [1, 2, 3, 4]
- // const [num1, num2, ...restArr] = arr
- // console.log(num1, num2)
- // console.log(restArr)
- // const newArr = [...arr, 5]
- // console.log(newArr)
- // console.log(arr)
- // function viewPerson({ firstName, lastName, age }) {
- // return firstName, lastName, age
- // }
- // const person = {
- // firstName: 'samim',
- // lastName: 'Hasan',
- // age: 30,
- // }
- // console.log(viewPerson(person))
- //callback
- //promise
- // fetch('https://jsonplaceholder.typicode.com/todos/1')
- // .then((response) => response.json())
- // .then((json) => console.log(json))
- // .catch(err => console.log(err))
- //async await
- // async function run(){
- // try{
- // const res = await fetch('https://jsonplaceholder.typicode.com/todos/1')
- // const data = await res.json()
- // console.log(data)
- // }catch(err){
- // console.log(err)
- // }
- // }
- // run()
- class Person {
- //filed/property
- // name = 'samim'
- // age = 30
- constructor(mName, mAge) {
- console.log(mName, mAge)
- this.name = mName
- this.age = mAge
- }
- //method
- showInfo() {
- return this.name + '-' + this.age
- }
- }
- // const person = new Person('khalil', 35)
- // console.log(person)
- // console.log(person.name)
- // console.log(person.age)
- // console.log(person.showInfo())
- //subclass(child class) and inheritance
- class Student extends Person {
- constructor(name, age, course) {
- super(name, age)
- this.course = course
- }
- showCoursesInfo() {
- return super.showInfo() + ' ' + this.course
- }
- }
- const student = new Student('anis', 25, 'React Student')
- console.log(student)
- console.log(student.showCoursesInfo())
- console.log(student)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement