JavaScript - Code Academy Flashcards

(32 cards)

1
Q

Access a single dimensional array element

A

array[index]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a single dimensional array

A

var arrayName = [element1, element2, …, elementN]

var myArray = new Array(45 , “Hello World!” , true , 3.2 , undefined);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a multi dimensional array

A

var arrayName = [[1, 2, 3], [1, 2, 3,], [1, 2, 3]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Create an array using an array constructor

A

var stuff = new Array();

stuff[0] = 1;
stuff[1] = 2;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Access a nested array element

A

array[index][index]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Boolean literals

A

True

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Boolean logical operators

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Boolean comparison operators

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Boolean - == vs. ===

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Single line comment

A

//

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Multi-line comment

A

/*

Text
text

*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Print text to console

A

console.log(‘text’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Console timer

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Writing a function

A

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;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Calling a function

A

functionName(argument1, argument2, …, argumentN);

greet("Anonymous");
// Hello Anonymous!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Function hoisting

A

The two ways of declaring functions produce different results. Declaring a function one way “hoists” it to the top of the call, and makes it available before it’s actually defined.

hoistedFunction(); 
// Hello! I am defined immediately!
notHoistedFunction(); 
// ReferenceError: notHoistedFunction is not defined
function hoistedFunction () {
  console.log('Hello! I am defined immediately!');
}
var notHoistedFunction = function () {
  console.log('I am not defined immediately.');
}
17
Q

If statemetns

A

“If” statements simply state that if this condition is true , do this , else do something else ( or nothing ) . It occurs in varied forms.

if (condition1) {
  statement1;
} else if (condition2) {
  statement2;
} else {
  statement3;
}
18
Q

For loops

A

You use for loops, if you know how often you’ll loop. The most often used varName in loops is “i”.

for ([var i = startValue];[i

19
Q

While loops

A

You use while loops, if you don’t know how often you’ll loop.

while (condition) {
  // Your code here
}

EXAMPLE
var x = 0;
while (x

20
Q

Do while loops

A

You use do while loops, if you have to loop at least once, but if you don’t know how often.

do {
  // Your code here
} while (condition);
var x = 0;
do {
    console.log(x);  // Prints numbers from 0 to 4
    x++;
} while (x
21
Q

Math - Returns a random number between 0 and 1

A

Math.random();

22
Q

Math - Returns the largest number less than or equal to a number

A

Math.floor(expression)

23
Q

Math - Returns base raised to exponent

A

Math.pow(base, exponent)

24
Q

Math - Returns smallest integer greater than or equal to a number

A

Math.ceil(expression)

25
Math - Returns square root of a number
Math.sqrt(expresssion)
26
Numbers - Returns the remainder left after dividing the left hand side with the right hand side.
number1 % number2
27
Numbers - Returns true if the given number is not a number, else returns false.
isNaN([value])
28
Numbers - prefix and post fix increment/decrement
--variable //Prefix Decrement ++variable //Prefix Increment variable-- //Postfix Decrement variable++ //Postfix Increment
29
Object literal
``` { "property 1" : value1; property2 : value2; number: value3; } ``` ``` EXAMPLE var obj = { name: "Bob", married: true, "mother's name": "Alice", "year of birth": 1987, getAge: function () { return 2012 - obj["year of birth"]; }, 1: 'one' }; ```
30
Property access
name1[string] name2.identifier EXAMPLE obj['name']; // 'Bob' obj.name; // 'Bob' obj.getAge(); // 24
31
Class
A class can be thought of as a template to create many objects with similar qualities. Classes are a fundamental component of object-oriented programming (OOP). SubClass.prototype = new SuperClass(); ``` EXAMPLE var Lieutenant = function (age) { this.rank = "Lieutenant"; this.age = age; }; ``` Lieutenant.prototype = new PoliceOfficer(); Lieutenant.prototype.getRank = function () { return this.rank; }; var John = new Lieutenant(67); John.getJob(); // 'Police Officer' John.getRank(); // 'Lieutenant' John.retire(); // true
32
Popup boxes - alerts
Display an alert dialog with the specified message and an OK button. alert(message); alert(variable_name)