Training JavaScript

Foundation

Tiven Wang

JavaScript Series

Language basics

Variable

Variable

JavaScript is a loosely typed or a dynamic language.

Primitive

  • string
  • number
  • boolean
  • null
  • undefined
  • symbol (new in ECMAScript 6)

other

  • Object

Variable

boolean Conversions

false

  • The empty string ""
  • null
  • undefined
  • The number 0
  • The number NaN
  • The boolean false

true

  • The string "0"
  • The string "false"
  • The string " "
  • The number -1

Object

An object is a collection of related data and/or functionality (which usually consists of several variables and functions — which are called properties and methods when they are inside objects.)

Array is Object


var person = {
  name: ['Bob', 'Smith'],
  age: 32,
  gender: 'male',
  interests: ['music', 'skiing'],
  bio: function() {
    alert(this.name[0] + ' ' + this.name[1] + ' is ' + this.age + ' years old. He likes ' + this.interests[0] + ' and ' + this.interests[1] + '.');
  },
  greeting: function() {
    alert('Hi! I\'m ' + this.name[0] + '.');
  }
};

Function

points

  • How to define and use a function
  • Passing parameters to a function
  • Pre-defined functions that are available to you "for free"
  • The scope of variables in JavaScript
  • The concept that functions are just data, albeit a special type of data
  • Function has prototype that is a Object
  • new Function = Object
  • call Function

Function

points

  • Using anonymous functions
  • Callbacks
  • Self-invoking functions
  • Inner functions (functions defined inside functions)
  • Functions that return functions
  • Functions that redefine themselves
  • Closures

Scope

  • ()
  • function f(){}()
  • (function f(){}())

Prototype

Object.prototype is a object: Object is a inner Function

Function.prototype is a function: Function is a inner Function

Closure

## TypeScript [TypeScript](https://zh.wikipedia.org/wiki/TypeScript) [CoffeeScript](http://coffeescript.org/) [ES6](http://es6-features.org) `npm install -g typescript` `tsc helloworld.ts` `node helloworld.js`

Node.js

Thank you

@tiven.wang