Javascript Cheat-Sheet: Var Function

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

JavaScript Cheat-Sheet

DefiningVariables ArgumentsandParameters

varhello
=
"
helloWorld
"; Parameter:
Placeholderforfuturevalue

BasicValueTypes functionexample
(
value1
,value2
){
console
.
log
(
value1
);
Numbers console
.
log
(
value2
);
Strings }
Booleans Arguments :
Thevaluespassedtothe
Objects function.
Functions
Arrays example
("
stringValue
",
22
);
Undefined
Null if/elseStatements

Functions if
(expression returns
true
){

// run this code
Definition }
else{

// run this code
functiondemo
(
arguments
){ }
// execute code

// use arguments
if/elseif/elseStatements
}
if(
expression returns true
){

`return`
Keyword:


// run this code
Stopsexecutionofcode }else
if
(expression returns
true
){
Returnsvaluetoanewlineofcode
// run this code
UsedinFunctionstoreturnvalues }else{

// run this code

console.log(
someValue ) }

Displays values
Doesntreturnvalues ConditionalOperators
Similartowindowshopping
>
GreaterThan
Invoking/Calling/Applying <
LessThan
>=GreaterThanorEqualTo
UseParenthesis <=LessThanorEqualTo
Runsthecodeofthefunction === IdentityOperator(isequalto?)
!==NotEqualTo
Arrays
demo
(
arguments
)

LogicalOperators
Avaluethatstores
multiple
values
&&AND: truevalue&&truevalue
||OR:
truevalue||falsevalue EmptyArray
!NOT:Togglestrueandfalse
varmyArray
=
[];

Strings
ValuesinArray


Aseriesofcharactersenclosedbya
()or()
varmyArray
=
["
a
",
5
,
true
];
'
hello
';
"
hello
";
AccessIndividualCharacters
ZeroBasedIndex
BracketNotation

varhello
=
"
helloWorld
";
hello
[
0
];
// returns 'h';

Loops

forloop
for
(
declare vars
;condition
;count
){
// run code
}
example
for
(
vari
=
0
;i
<
10
;i
++){
// run code
}


whileloop

varcounter
=
0;
while
(
condition
){
// run code
counter
++
}

You might also like