JavaScript - Code Academy Flashcards
Access a single dimensional array element
array[index]
Create a single dimensional array
var arrayName = [element1, element2, …, elementN]
var myArray = new Array(45 , “Hello World!” , true , 3.2 , undefined);
Create a multi dimensional array
var arrayName = [[1, 2, 3], [1, 2, 3,], [1, 2, 3]]
Create an array using an array constructor
var stuff = new Array();
stuff[0] = 1; stuff[1] = 2;
Access a nested array element
array[index][index]
Boolean literals
True
False
Boolean logical operators
expression1 && expression2 //returns true if both the expressions evaluate to true
expression3 || expression4 // return true if either one of the expression evaluates to true
!expression5 // returns the opposite boolean value of the expression
EXAMPLES
if ( true && false )alert("Not executed!"); //because the second expression is false
if( false || true )alert("Executed!"); //because any one of the expression is true
if( !false )alert("Executed!"); // because !false evaluates to true
Boolean comparison operators
x === y // returns true if two things are equal
x !== y // returns true if two things are not equal
x = y // returns true if x is greater than or equal to y
x y // returns true if x is greater than y
Boolean - == vs. ===
A simple explanation would be that == does just value checking ( no type checking ) , whereas , === does both value checking and type checking .
expression == expression
expression === expression
EXAMPLES
‘1’ == 1 //true (same value)
‘1’ === 1 // false (not the same type)
Single line comment
//
Multi-line comment
/*
Text
text
*/
Print text to console
console.log(‘text’);
Console timer
This function starts a timer which is useful for tracking how long an operation takes to happen.You give each timer a unique name, and may have up to 10,000 timers running on a given page.
console.time(timerName);
Writing a function
A function is a JavaScript procedure—a set of statements that performs a task or calculates a value.
function functionName(argument1, argumentN){ statement1; statement2; statement3; }
Calling a function
functionName(argument1, argument2, …, argumentN);
greet("Anonymous"); // Hello Anonymous!