This is a draft cheat sheet. It is a work in progress and is not finished yet.
Types of data
string |
"" |
var name = "John Doe"; |
integer |
45 |
var years = 14; |
float |
12.5 |
var price = 405.17; |
boolean |
true/false |
var registered = true; |
array |
[] |
var cars = ['Ford', 'Fiat', 'Mercedes']; |
object |
{} |
var user = { name: "John", lastname:"Doe" } |
Functions
declaration |
function doSomething() { console.log('done'); } |
declaration as expression same as above |
var doSomething = function(){ console.log('done'); } |
anonimous function |
function(){ console.log('done'); } |
calling (executing) function |
doSomething(); |
function with parameters |
function doSomething(param1, param2) { param1=param2 + "some text"; console.log('param2:' + param1); } |
calling function with parameters |
doSomething('value of param1', 'value of param2'); |
calling function with parameters sending variables |
var a = 1; var b = 2; doSomething(p, d); |
inside of function p will be 1 and d will be 2 |
function that returns |
function doSomething() { var result = "result to be returned"; return result; } |
getting result from a function function needs to have return |
var fresult = dosomething(); |
getting result from anonimous function function needs to have return |
var fresult = function() { var result = "result to be returned"; return result; } |
fresult will be "result to be returned" |
|