Hello 'JS' World!

What is JavaScript?

JavaScript, not to be confused with Java (same goes with Hamburger), was created in 10 days in May 1995 by Brendan Eich, then working at Netscape and now of Mozilla. JavaScript was not always known as JavaScript: the original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape.

What are you going to learn today

  • Functions
  • Closure
  • Objects
  • Inheritance
  • Promise
  • Events
  • jQuery
  • More functions
  • some ES6

Some tips where to go next, at end of the session.

Eventually we will also get our hands on real code;

Functions with ES6

"Those who are unaware they are walking in darkness will never seek the light"

Objects

So what is an Object

"Its a set of key value pairs. Each key can be assigned any value type"

Important note's:

  • Primitives are passed by value, objects are passed by reference
  • `function`'s are regular objects
  • `this` keyword depends on the object, not where the function was defined

Tip: use strict mode to prevent mistakes

Inheritance

Prototypical method

Polymorphism and Method Overriding

means, same name but different behaviour. Polymorphism cant be there without `Inheritance`

Polymorphism

Classical method

  • new constructor
  • instanceof
Promise
Array methods

slice, split, reduce - angular alike filter

001_array-slice.js

Events and jQuery
jQuery slider
jQuery Todo with localstorage

Some Helper Functions

non-functional (bad)

Avoid mutation (bad)

No mutation (good)

Object.assign

Impure function

Avoid side effects, use pure functions

Pure function

Functions containing one or more free variables are called 'closures'

Closure

Closures are functions that refer to free variables. In other words, these functions 'remember' the environment in which they were created.

Higher-order functions

aka Currying, is your function can pass through the application and gradually receive the arguments.

Recursion

002_recursion.js