JavaScript Flashcards

1
Q

Syntax: function

A

function functionName(params) {

};

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

Syntax: print “Hello”

A

console.log(“Hello”)

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

what does the var keyword do?

A

creates a variable in current scope

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

Syntax: random number

A

Math.random() == 0-1

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

Syntax: for loop

A
for (var counter = 1; counter < 6; counter++) {  
;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax: add to end of an array

A

array.push(‘end’);

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

Syntax: while loop

A

while (true){
;
}

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

== vs ===

A

=== is faster, because == does type conversions

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

Syntax: do/while

A

do {
;
} while (condition);

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

Math.floor()

A

rounds a number down to its nearest integer

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

Syntax: If/else if/else

A

if () {
} else if () {
} else {
}

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

isNaN()

A

returns true if arg is not a number, false if it is

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

Syntax: switch

A
switch(val_to_check){
    case 'string':
        ;
        break;
    default:
        ;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Syntax: constructing an instance of an object

A

var myObj = new Object();

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

Syntax: Object constructor

A
function myObj(args) {
    this.args = args;
    this.myFunction = function() {
    };
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Syntax: for/in loop

A

for (var x in object) {
;
}

17
Q

Method vs function

A

method is a function associated with a certain object

18
Q

Literal constructor vs Constructor notation

A
obj = {property:value, property:value}
vs
function obj(property1, property2) {this.property1 = property1; this.property2 = property2;}
19
Q

Syntax: determine type of Obj

A

typeof Obj

20
Q

Syntax: determine whether an Obj has a property

A

Obj.hasOwnProperty(‘name’)

21
Q

Syntax: add a property or method to a class (and every instance of that class)

A

Class.prototype.property_or_method

22
Q

Syntax: Class inherits from Parent

A

Child.prototype = new Parent();

23
Q

Syntax: Making a variable private

A

In class declaration, instead of “this.name = name;” use “var name = name”