App Academy - WEEK 6 DAY 1
This is the first JavaScript day that has actually been fun. We got to implement Asteroids. I just wanted to stay and work on it all evening. Can't wait to have more time to prettify my game. It'd going to be badass and nothing less :)
=== compares type and value
JS would happily take extra or fewer arguments than specified
fewer - it returns undefined. It can be annoying to debug because it doesn't throw any errors.
more - just like this, a function also has a keyword arguments, which returns an array-like object of all passed arguments.
function logArguments () { console.log(arguments); }; logArguments("boop", "candle", 31, 200); // { '0': 'boop', '1': 'candle', '2': 31, '3': 200 }
functional programming := an alternative to object-oriented programming. It focuses on passing functions around, rather than objects.
currying := the process of decomposing a function that takes multiple arguments into one that takes single arguments successively until it has the sufficient number of arguments to run.
function sumThree(num1, num2, num3) { return num1 + num2 + num3; } sumThree(4, 20, 6); // == 30 sumThree.curry(3)(4)(20)(6); // == 30
Immediately Invoked Function Expression (IIFE, pronounced "iffy")
each source file consists of all the code written in an anonymous function, which is immediately evaluated
this allows for private variables within a source file
Asynchronous Client-side Code
window.setInterval is used instead of while loops so that the browser tab doesn't get entirely locked up
Don't use prompt. This prompts the user to type in text and because it waits for user input, it blocks the entire page.
input in JS is typically handled asynchronously: a function, called a handler, is called by the browser when an event occurs.
JS lets us ask the browser to notify us of events
JS has only one type of numeric data: float.