Basic Flashcards

1
Q

push()

A

Adds item to the end of an array.

i.e. arr.push(“name”);

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

pop()

A

Removes item from the end of an array.
i.e. arr.pop();
item can also be assigned to a variable.
i.e. myVar = arr.pop();

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

shift()

A

Adds item to the front of an array.

i.e. arr.shift(“name”);

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

unshift()

A

Removes item from the front of an array.
i.e. arr.unshift();
item can also be assigned to a variable.
i.e. myVar = arr.unshift();

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

length

A

Can be used for the length of a string or an array.

i.e. myString.length

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

===

A

Strict Equality tests both data and type. It will not convert a string to a number like == will.

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

!==

A

Strict Inequality tests both data and type. It will not convert a string to a number like != will.

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

How are case statements evaluated?

A

With strict equality, ===

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

What are the two ways to access the properties of an object?

A
Dot Notation: myObj.property;
or
Bracket Notation: myObj["property"];
Bracket notation can also be used with a variable.
myProp="property";
myObj[myProp];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you delete a property from an object?

A

delete myObj.property;

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

How to you add a property to an object?

A

myObj.myProp = “property”;

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

How do you check if a property exists on an object?

A

myObj.hasOwnProperty(“property”);

returns true if property exists.

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

How do you generate a random number?

A

Math.random();

Returns a whole number between 0 and almost 1, but it doesn’t actually get to 1.

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

How do you round down to the next whole number?

A

Math.floor();

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

How do you generate a whole number between 0 and 9?

A

Math.floor(Math.random() * 10);

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

How do you generate a random whole number within a range?

A

Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;

17
Q

How do you initialize and object with a constructor?

A
var MotorBike = function() {
  this.wheels=2;
  this.engines=1;
  this.seats=1;
};
18
Q

describe the map function.

A

The map function iterates through an array and modifies each item by the function.

19
Q

describe the filter function

A

The filter function iterates through an array and creates a new array with items that match the filter callback.

//this filter creates a new array that includes all values not equal to 5.
array = array.filter(function(val) {
  return val !== 5;
});
20
Q

describe the sort function

A

The sort function sorts the array in place and uses a text sort if no parameters are passed. Passing in two paramaters lets you sort numbers in either direction.

//sort from largest to smallest
array.sort(function(a,b){
  return b-a;
});
//sort from smallest to largest 
array.sort(function(a,b){
  return a-b;
});
21
Q

describe reverse function

A

The reverse function reverses the order of items in an array in place.
myArray.reverse();
but can also return a reversed array
newArray = array.reverse();

22
Q

describe concat function

A

The concat function creates a new array by combining two arrays together.

newArray = oldArray.concat(otherArray);

23
Q

Describe the slice function.

A

The slice function can work on strings or arrays. It can slice a substring from a string into a new string or it can slice a section of an array into a new array. The parameters are Start and End.

var a = ['zero', 'one', 'two', 'three'];
var sliced = a.slice(1, 3);
24
Q

Describe the splice function.

A

Splice can either insert items into an array at a specific point or it can delete items from an array starting at an index and removing the specified number.

var myFish = [‘angel’, ‘clown’, ‘mandarin’, ‘sturgeon’];

myFish.splice(2, 0, 'drum'); // insert 'drum' at 2-index position
// myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"]
myFish.splice(2, 1); // remove 1 item at 2-index position (that is, "drum")
// myFish is ["angel", "clown", "mandarin", "sturgeon"]
25
Q

Immutable Datatype.

A

A datatype that cannot be changed. A string is an immutable datatype, so when you concatenate a string, you are really copying the data from the original string and the appended data all into a new string.

26
Q

Mutable Datatype.

A

A datatype that can be changed. User defined objects are mutable, and setting an object = to another object results in a reference, so if there is a change, both will reflect the change.

27
Q

Describe the split function

A

The split function takes a string and splits it into an array based on a single character.
array = myString.split(‘ ‘);

28
Q

Descibe the join function

A

The join function combines all the strings in an array with a specified string between each one.

var veggies = ["Celery", "Radish", "Carrot", "Potato"];
var salad = veggies.join(" and ");