mode 4 JS II Flashcards

1
Q

What is an array?

A
  • a group of data entries

- Each data entry has an index associated with it. indeces begin with (0) to (arraySize -1)

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

how do we declare an array?

how do you see all the contents of an array?

how do you obtain the length of the array (the # of elements)?

how do you access elements in an array?

A
how do we declare an array?
var arrayOne= ['Billy', 'Katherine'];
// remember, JS is loosely typed
var arrayTwo= ['Billy', 'Katherine', 77, false];
//                             0           1         2    3
// how do you see all the contents of an array?
console.log(arrayTwo);
// how do you obtain the length of the array (the # of elements)?
//console.log(arrayTwo.length); // prints "4"
// how do you access elements in an array?
//console.log(arrayTwo[0]); // prints "Billy"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what if you attempt to access an element that doesn’t exist?

what if you attempt to update an element that doesn’t exist?

how do I dynamically remove elements from an array?

A
//what if you attempt to access an element that doesn't exist?
var arrayOne= ['Billy', 'Katherine'];
// remember, JS is loosely typed
var arrayTwo= ['Billy', 'Katherine', 77, false];
//                             0           1         2    3

console.log(arrayTwo[50]); //prints “undefined”

//what if you attempt to update an element that doesn't exist?
arrayTwo[6]="does this work?";
// console.log(arrayTwo);
// console.log(arrayTwo[5]); //prints "undefined"
// console.log(arrayTwo[6]); //prints "does this work?"
//how do I dynamically remove elements from an array?
var arrayDelete = [6, 8, 10, 12];
delete arrayDelete[1];
console.log(arrayDelete); 
console.log(arrayDelete[1]); //prints "undefined"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an object?

A
  • a model of a real world physical object
    - it has state and behavior
    - in JS, objects are key-value pairs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how do I create an object?

A
var objectOne = {
    // to declare a member of an object, you use key-value pairs
    // attribute: value
name: "Danny Boy",
'ability': 'electromagnetism',
'official bounty': 250000,
    // this is how you'd add a method
    doCrimeMethod: function(){
        // method logic
        console.log("inside doCrimeMethod()")
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a function?

A
  • a reusable block of code
    • it performs some service for the rest of the application
    (Note: function vs method. A method is just a function that is attached to an object)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the different between an argument and a parameter?

A
  • parameters are used to declare WHICH variables a function/method will use.
    • arguments are the actual values passed into a function/method as it is invoked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do I declare a function?

A

function myFunction(){}

//I can also give a function parameters
var myFunctionTwo = function (lePokemans, leMoveSet){
console.log(“The objective best pokemon is: “+lePokemans);
console.log(leMoveSet);

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

What is control flow?

A
  • control flow are a series of functionalities that allow the developers to alter the logical flow of the application
    • normally in an application lines of logic are read top to bottom. Using control flow we can alter the way the lines of logic are ready. We can make lines of code repeat or even be skipped
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Keywords associated with control flow?

A
  • if, else if, else
    • while, for, do-while, foreach
    • switch
    • break, continue
    • ”?” and the ternary operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the TRUTHY values in JS?

A

Anything that isn’t a FALSEY value

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

What are the FALSEY values in JS?

A

false, 0, “”, null, NaN, undefined

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

Short-circuiting

A

Short circuiting

T and T     =   T
T and F     =   F
F and T     =   F
F and F     =   F

T or T     =   T
T or F     =   T
F or T     =   T
F or F     =   F

shortcircuiting operators:   &&  , ||
bitwise operators:   & , |,  ^, etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a string?

A

a primitive datatype in JS

it represents a series of characters

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

how do I create a string?

A

var name= ‘Billy “The Warden”’;

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

COMPLEX STRINGS

A

backtiks aka template literals will evaluate an expression with ${}

17
Q

What is ECMAScript

A

ECMAScript is a standardization of functionalities that scripting languages should have.
Various versions of ECMAScript add different functionalities.
e.g. it can be denoted like “ES6” or “ES2015” or “ECMAScript2015”

18
Q

Why do we use “use strict”;

A

-“use strict” is used to stop devs from declaring variables WITHOUT using “let” or “const” or “var”

“use strict”;