Javascript Cheat Sheet

ADVERTISEMENT

Javascript cheat sheet
Free functions:
In JavaScript, functions like to run wild and free, belonging to the wilderness of the code, mating with
each other like hippie binaries. These are cells. The building blocks of the language.
function
iShitYouNot(aparameter)
//notice no return type and no parameter
//types.
{
var
x = 1;
//Variable declaration
for(var
i = 0; i < aparamenter; ++i)
{
x = x*(x+1);
}
return
x;
//Guess what this does?
}//Curly brackets FTW
function
iPrint()
{
console.log("Blah");
//System.out.println(“Blah”);
}
Free code:
These are bacteria. They don’t belong to any organisms. They’re just waiting to be parsed and executed.
As soon as the js gets loaded, they will run when you hit them. As such there is no
main
, there is only
free code waiting to be executed. There is one pitfall to parsing though:
ICallTheFuture();
//Causes parse ERROR
function
ICallTheFuture()
{
console.log("You can't call me yet, I haven't been
parsed");
}
------------------------------------------------------------------------
function
ICallThePast()
{
console.log("Good
job");
}
ICallThePast();//This is legal. The following will be executed at load.
var
x = 1;
for(var
i = 0; i < aparamenter; ++i)
{
x = x*(x+1);
}
console.log(x);

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3