WebFund 2016W Lecture 2

From Soma-notes
Revision as of 15:44, 14 January 2016 by Zero (talk | contribs) (Added section on Node.js.)

Video

The video from the lecture given on January 12, 2016 is now available.

Notes

In-class Notes

Lecture #2
----------
JavaScript

* no declared types
  - strings
  - objects
  - arrays
  - numbers (floats)
  - boolean

With Node
 - asynchronous (non-blocking) I/O


Student Notes

JavaScript: As a Language

  • JavaScript has nothing to do with Java.
    • Why is it even called JavaScript then? At first it wasn't; it was developed as Mocha, changed to LiveScript and then finally renamed to JavaScript due to an agreement with Sun (acquired by Oracle).<ref>[1]</ref>
  • The only similarity between Java/JavaScript is some of the syntax, but that can be said for a lot of languages.
  • What's different about JavaScript?
    • No declared data types; it's a "loose" language.
      • Instead of int i = 0, it's simply var i = 0.
    • There's seven data types<ref>[2]</ref> (examples in brackets)
      • Boolean (true, false)
      • Number (3.1337, 1337, etc. There's no integer or long, everything is a float)
      • String ("Dave")
      • Symbol
      • Object
      • Null
      • Undefined

How should I learn JavaScript?

  • Practice! While attending the lectures is a great start, you will have to practice outside of class. This will not be graded, but will ultimately affect your performance in the course (and in the workplace).
    • Codecademy has a lot of good resources for beginners.
    • For more advanced students, check on GitHub to see if there's any projects you're interested in contribution to. If you plan to work in web development, it's very likely you will be asked in an interview if you've contributed to any open source projects (having a good portfolio will help a lot in getting a first job).

Working with Variables

If you've previously worked with Java, the first large difference you've noticed is likely that variables are very "flexible".

  • If you attempt to use a variable that has not been declared, you will not get a compiler error. Instead, the type undefined will be returned. This can making debugging a bit of a challenge!
  • Likewise with most languages, a symbol (e.g., x) can only reference one object.
  • You can have several types of data inside single object (e.g., x.y, x.y.z, x.y.x.qwerty, etc).
  • x.size (dot notation) is the same as x["size"] (array notation).

Regular Expressions (Regex)

While this topic is technically outside of the course material, you will likely need to use it in some assignments. Regex is the same across different languages, so you will not need to relearn it all for every language.

https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions

Node.js

Node.js is designed to provide a server side environment of JavaScript. Instead of using Google's V8 JavaScript inside Chrome/Chromium, Node.js uses the V8 engine directly. Because Node.js is meant to be used outside of the browser, there's some slightly differences.

  • Contains a package manager called npm to manage dependencies (libraries).
  • Has specialized libraries for networking, file system access, etc that you usually wouldn't find in a browser (mostly for security reasons).
  • Has no default graphic frontend such as WebKit (although there are libraries to provide that if you wish).
Getting started with Node.js

To open up Read-Eval-Print-Loop (REPL), run node in a terminal. For more details on setting your environment up, see Tutorial 1

References

1 | references-column-count references-column-count-{{{1}}} }} }} }}" {{#if: | style="-moz-column-width:{{{colwidth}}}; column-width:{{{colwidth}}};" | {{#if: | style="-moz-column-count:{{{1}}}; column-count:{{{1}}};" }} }}> <references group=""></references>