JavaScript - Basic Flashcards

1
Q

pop() Method

A

remove the last element of an array

Example:
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.pop();

Result:
Banana,Orange,Apple

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

push() Method

A

Add a new item to the end of an array

Example:
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.push(“Kiwi”);

Result:
Banana,Orange,Apple,Mango,Kiwi

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

join() Method

A

Joins the element of an array into a string

Example:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();

Result:
Banana,Orange,Apple,Mango

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

reverse() Method

A

Reverse the order of the elements in an array

Example:
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.reverse();

Result:
Mango,Apple,Orange,Banana

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

split() Method

A

Splits string into an array of substrings

Example:
var str = "How are you doing today?";
var res = str.split(" ");

Result:
How,are,you,doing,today?

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

round() Method

A

Math.round(x) (aka round() Method)

Example:
Math.round(2.5);

Result:
3

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

parseInt() Function

A

The parseInt() function parses a string and returns an integer.

Example:

a) var c = parseInt(“10.33”) + “<br></br>”;
b) var d = parseInt(“34 45 66”) + “<br></br>”;

Result:
10
34

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

n!

A

Factorial. An example is:

5! = 1 * 2 * 3 * 4 * 5 = 120

function factorialize(num) {
  var factorial = 1;
  for (var i = 2; i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

String.replace() Method

A

Return a string where “Microsoft” is replaced with “W3Schools”:

var str = "Visit Microsoft!";
var res = str.replace("Microsoft", "W3Schools");

The result of res will be:

Visit W3Schools!

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

String.toLowerCase() Method

A

Convert the string to lowercase letters:

var str = "Hello World!";
var res = str.toLowerCase();

The result of res will be:

hello world!

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

String slice() Method

A

Extract parts of a string:

var str = "Hello world!";
var res = str.slice(1,5);

The result of res will be:

ello

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

RegExp Object

A

A regular expression is an object that describes a pattern of characters.

Regular expressions are used to perform pattern-matching and “search-and-replace” functions on text.

http://www.w3schools.com/jsref/jsref_obj_regexp.asp

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

switch statement

A

[JS Control Flow] Switch allows you to preset a number of options (called cases), then check an expression to see if it matches any of them.

switch (/*Some expression*/) {
    case 'option1':
        // Do something
        break;
    case 'option2':
        // Do something else
        break;
    case 'option3':
        // Do a third thing
        break;
    default:
       // Do yet another thing
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What will the following expression return:

true && false;

A

False

true && true; // => true
true && false; // => false
false && true; // => false
false && false; // => false

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

What will the following expression return:

false || true;

A

True

true || true; // => true
true || false; // => true
false || true; // => true
false || false; // => false

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

What will the following expression return:

!false; // => true

A

True

!true; // => false
!false; // => true

17
Q

Create an array called ‘list’ with 3 items in it.

A

var list = [“errands”, “cleaning”, “homework”];

18
Q

Write the code to log to the console each item of the following array:

var languages = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”];

A

for (var i = 0; i

19
Q

What is a heterogeneous array?

A

An array that contains a mixture of data types like:

var mix = [42, true, “towel”];

20
Q

What is a two-dimensional array?

A

An array inside an array, in this case an array nested one layer deep:

var twoDimensional = [[1, 1], [1, 1]];

21
Q

What is a jagged array?

A

An array that includes arrays of different lengths e.g.

var jagged = [[“name”, “gender”, 30], [“name”, “gender”], 33, true];

22
Q

Write an example of object literal notation by creating the object “me” and giving it two keys.

A
var me = {
  name: "bubba",
  age: 31
}
23
Q

Create a new object called “myObj” using the object constructor. Then, assign a name to myObj using the shorthand version.

A

var myObj = new Object();

myObj.name = “Bubba”;

24
Q

for key in object

A

for key in object describes the iteration through all the keys of an object. Because this is not sequentially indexed, in is the control. Objects generally have a finite number of properties in them, and this loop susses them out, one at a time.

25
Q

Create an object called “friends” and create two objects inside of that named “bill” and “steve”.

Each friend will need a first name, last name, number and address.

Make sure the address is an array.

A
var friends = {
    bill: {
        firstName: 'bill',
        lastName: 'smith',
        number: '111-111-1111',
        address: ['One Apple Drive', 'Cupertino', 'CA', '12345']
    },
    steve: {
        firstName: 'steve',
        lastName: 'ferguson',
        number: '22-222-2222',
        address: ['One Facebook Way', 'Palo Alto', 'CA', '54321']
    }
};
26
Q

Create a function that will print out all entries in an object called “friends”.

A
var list = function(friends) {
    for (var i in friends) {
        console.log(i);
    }
}
27
Q

What is a for/in loop look like and what does it do?

A
for (var key in object) {
  // Access that key's value
  // with object[key]
}

*the “key” bit can be any placeholder name you like. It’s sort of like when you put a placeholder parameter name in a function that takes arguments.

28
Q

Definite Object Methods

A

Object methods are actions that can be performed on objects.

Object properties can be both primitive values, other objects, and functions.

An object method is an object property containing a function definition

29
Q

const

A

ES6. const means that the variable can’t be reassigned.

In other words, const is a signal that the variable won’t be reassigned.

30
Q

let

A

ES6. let, is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm.

It also signals that the variable will be used only in the block it’s defined in, which is not always the entire containing function.