Javascript Flashcards

1
Q

What is JavaScript?

A

JavaScript allows us to create incredibly diverse applications that run in the browser, on the back-end as NodeJS, on the desktop, and on mobile devices. It’s a flexible language, allowing us to program in many different styles — functional and object-oriented, in particular — mixing and matching concepts to adapt to our needs. It’s powerful, scalable, and has a robust community of developers churning out new code and advancing the language. And, finally, it’s a great first or second language to learn.

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

What are variables?

A
  • Hold primitive or compound data

- Types: Let & Const

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

What is Let?

A
  • Declares variable that can be changed later
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Const?

A
  • Variable that cannot be changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 2 types of data? (2)

A
  • Primitive

- Compound

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

What are the 2 types of data? (2)

A
  • Primitive

- Compound

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

What is Compound data?

A
  • array

- object

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

Define DOM

A
  • Document Object Model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the DOM?

A

__

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

How to write an IF statement in JS

A

__

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

How to insert JS?

A
  • Insert tag just before </body> of HTML doc containing link to .js file.
  • real-life apps bundle many .js files into one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is asynchronous JS?

A
  • The process of making requests for additional data from a loaded page
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define AJAX

A
  • Asynchronous JavaScript and XML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to write an IF statement in JS

A
if (condition) {
    // Block of code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is ECMAScript?

A
  • JavaScript specification revised every yr since ES2015-ES2020
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can I manipulate the DOM with JS?

A
  • Open Chrome DevTools with Ctrl+Shift+J & open the JS Console
17
Q

What is a strict equality operator? (ex)

A
  • returns true if two values are equal without performing type conversions
  • 42 === 42
    true
  • strict inequality operator is !==
18
Q

How to write an ELSE statement in JS

A

const age = 14;

let isAdult;

if (age >= 18) {
    isAdult = true;
} else {
    isAdult = false;
}
// => false
isAdult;
// => false
19
Q

How to write an ELSE IF statement in JS

A

const age = 20;

let isAdult, canWork, canEnlist, canDrink;

if (age >= 21) {
    isAdult = true;
    canWork = true;
    canEnlist = true;
    canDrink = true;
} else if (age >= 18) {
    isAdult = true;
    canWork = true;
    canEnlist = true;
} else if (age >= 16) {
    canWork = true;
}
// => true
isAdult;
// => true
canWork;
// => true
canEnlist;
// => true
canDrink;
// => undefined
20
Q

How to write a SWITCH statement in JS

A

const hunger = ‘famished’;

let food;

switch (hunger) {
    case 'light':
        food = 'grapes';
        break;
    case 'moderate':
        food = 'sushi';
        break;
    case 'famished':
        food = 'lasagna';
        break;
}
// => "lasagna"
food;
// => "lasagna"
21
Q

Ternary operator example

A

const age = 60;

const isAdult = age >= 18 ? true : false;

isAdult;
// => true
22
Q

How to write a function in JS?

A
function functionName(argument1, argument2, argument3) {
  body code goes here
}
23
Q

Objects

A

https://learn.co/tracks/cpb-v5/javascript/data-structures/objects

24
Q

For Loop

A
for (let i = 0; i < array.length; i++) {
  // Loop body
}
25
Q

While

A

while (j < myArray.length) {
console.log(myArray[j++]);
}

26
Q

How to iterate over an array

A

Use a for…of statement anytime you want to iterate over an array.

27
Q

How to iterate over an object

A
for (const  in ) {
  // Code in the statement body
}
28
Q

Traverse nested objects

A
userInfo.friends[0].firstName;
// => "Joe"
29
Q

Filter

A
[1, 2, 3, 4, 5].filter(function (num) { return num > 3; });
// => [4, 5]
30
Q

.map( )

A
const equippedEngineers = newEngineers.map(function(eng) {
    return Object.assign({}, eng, { equipment: 'Laptop' });
});
equippedEngineers;
// => [
//      { userID: 15, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" },
//      { userID: 63, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" },
//      { userID: 97, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" },
//      { userID: 12, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" },
//      { userID: 44, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" }
//    ]