export default function () {
  console.log('This is main for training JavaScript')
  otherFunc()
  callSubjects()
}

const callSubjects = function () {
  console.log('----- begin subjects -----')
  types()
  operators()
  controlStructure()
  objects()
  console.log('----- end subjects -----')
}

const otherFunc = function () {
  console.log('other Func!!')
}

export const secondFunction = function () {
  console.log('Second function!!')
}

const types = function () {
  console.log('------ begin type ------')
  // Number
  console.log(0.1 + 0.2)
  const stringNumber = '012'
  console.log(parseInt(stringNumber, 10))
  let count = 2
  console.log(count + '010') // cannot add but can concat.
  // String
  const word = 'hello'
  console.log(word.length)
  console.log(word.charAt(2))
  console.log(word.replace('ll', 'rr'))
  console.log(word.toUpperCase())
  // Boolean
  const falseFromfalse = Boolean(false)
  // const falseFromString = Boolean('false') // This is true
  const falseFrom0 = Boolean(0)
  const falseFromEmpty = Boolean('')
  const falseFromNaN = Boolean(NaN)
  const falseFromNull = Boolean(null)
  const falseFromUndef = Boolean(undefined)
  console.log(falseFromfalse)
  // console.log(falseFromString)
  console.log(falseFrom0)
  console.log(falseFromEmpty)
  console.log(falseFromNaN)
  console.log(falseFromNull)
  console.log(falseFromUndef)
}

const operators = function () {
  console.log('------ begin operators ------')

  let x = 5
  console.log(x)
  x += 5
  console.log(x)
  console.log('hello' + ' world') // hello world
  console.log(3 + 4 + 5)
  console.log('3' + 4 + 5)
  console.log(3 + 4 + '5')
  console.log(123 === '123') // false
  console.log(1 === true) // false
}

const controlStructure = function () {
  console.log('------ controlStructure ------')

  let name = 'kittens'
  if (name === 'puppies') {
    name += ' woof'
  } else if (name === 'kittens') {
    name += ' meow'
  } else {
    name += '!'
  }
  console.log(name)
  // loop
  const array = ['a', 'b', 'c']
  for (let value of array) {
    console.log(value)
  }
  let animal = {
    hand: 2,
    foot: 2,
    heart: 1
  }
  for (let property in animal) {
    console.log(property)
    console.log(animal[property]) // I can access value of property.
  }
  // short-circuit logic
  let o = {
    name: 'test o'
  }
  let u
  let n = o && o.name
  let n2 = u && u.name
  // let n3 = u.name // This will be TypeError, short-circuit can avoid this error.
  console.log('n is ' + n)
  console.log('n2 is ' + n2)
  // console.log(n3)
  let alreadyCached = 'Cached!'
  let notCached
  console.log(alreadyCached || (alreadyCached = 'Second cache'))
  console.log(notCached || (notCached = 'Second cache'))
  // Ternary operator (三項演算子)
  const age = 18
  console.log((age > 18) ? 'yes' : 'no')
  // Switch
  let action = 'eat'

  switch (action) {
    case 'draw':
      console.log('draw now!')
      break // In ESLint, Required break.
    case 'eat':
      console.log('eat now!')
      break
    default:
      console.log('nothing!')
  }
  switch (action) {
    case 'eat':
    case 'draw': // But, this is ok.
      console.log('eat and draw')
      break
    default:
      console.log('nothing')
  }
  let stringCondition = '4'
  switch (stringCondition) {
    case 4:
      console.log('match!')
      break
    default: // switch use '===' operator.
      console.log('not match!')
  }
}

const objects = function () {
  console.log('------ objects ------')
}

@@ -3461,18 +3461,546 @@
 bjects ------')%0A
+  let obj = %7B%0A    name: 'Carrot',%0A    _for: 'max',%0A    details: %7B%0A      color: 'orange',%0A      size: 12%0A    %7D%0A  %7D%0A  console.log('obj.name:' + obj.name)%0A  console.log('obj%5B%5C'name%5C'%5D:' + obj%5B'name'%5D)%0A  console.log('obj.details.color:' + obj.details.color)%0A  console.log('obj%5B%5C'details%5C'%5D%5B%5C'color%5C'%5D:' + obj%5B'details'%5D%5B'color'%5D)%0A%0A  // class%0A  class Polygon %7B%0A    constructor (height, width) %7B%0A      this.height = height%0A      this.width = width%0A    %7D%0A  %7D%0A  let p = new Polygon(12, 5)%0A  console.log(p.height)%0A  console.log(p.width)%0A
 %7D%0A

Add objects.