Quickstart Javascript

Thursday, September 10, 2015

Javascript Quickstart

Javascript Rocks

About:

  1. Javascript is not Java
  2. Similar names for marketing reasons
  3. Developed by Netscape in 1995 to create products and applications in the browser
  4. It's primarily client side
  5. Originally designed as a scripting language, it is actually a fully featured language

What can we do with it:

  1. Small enhancements such as infinite scrolling
  2. Parallax effects in the browser
  3. Build games with Javascript
  4. For the internet of things, robots, wearable tech and more
  5. Build full application, youtube application for playstation built with AngularJS

Hello World in Javascript


Use confirm function for confirm message box


Prompt allows the user to enter a value in message box


Some common operators


Echoing out a warning using the warn function


Use the error function on the console to log errors


Primitive data types


Variables, variable keyword is var


Control flow, if/else statements


Using else if


Basic fizzbuzz version between 0 and 5


Basic text game


Switch case statement example


Switch case with user input


For loops


More complex fizzbuzz version


While loops, do while always runs at least once


While loop example


Functions for readability and refactoring


More on functions


Arrays have a zero based index


Looping over an array


Text adventure game enhanced with some new features


Objects


Methods


Object literals


Object constructors are templates for creating objects


This and the global object, window dot works on our code because all objects are added to the global window object


Global scope, global variable, accessible from everywhere in the code


Local scope, variable declared inside function is a local variable


Variable declared without var is global variable


Understanding scope


Inner function has access to code in outer function


Outer function doesn't have access to inner function


Use JsLint to enforce a coding convention a good standard, it defines a professional subset of javascript


Get, set and delete


Object literals is an expressive notation for creating objects


Function of new prefix operator


There is only one number type in Javascript


Number methods add a method trunc to number prototype


Default Success Warning Important Info Inverse
B S W I ? O