Question:
I was trying to figure out way in javascript that a person would create a variable and then set it equal to a function. Cannot you just create a function called main().
function main() {
//....code here
}
code:
var main = function () {
var now = Date.now();
var delta = now - then;
update(delta / 1000);
render();
then = now;
// Request to do this again ASAP
requestAnimationFrame(main);
};*/
Code Here that I am not sure why it is enclosed in (...code here...)
(function() {
"use strict";
// Doesn't work because strict mode enforces
// the fact that the second example shouldn't work
if (true) {
function fn() {
// This won't run
console.log("doesn't work");
};
fn();
}
})();