JS Basics Flashcards

1
Q

What is a variable?

A

A variable is a way to store, change and use data.

“Named storage” for data

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

True or False when declaring multiple variables it is best practice to declare them on separate lines?

A

True

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

name: ‘Boba’;

This statement is an example of what?

A

A string literal

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

let age: 903;

This statement is an example of what?

A

A number literal

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

List some Data Types

A
String
Boolean
Number
undefined 
Null
Object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A ______ is a set of statements that calculates and returns a value or performs a task.

A

Function

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

What are we doing when we initialize a variable?

A

Assigning value to the variable

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

let listItem; is a _______, and listitem = 2; is a ______

A

let listItem; is a declaration and listItem = 2; is an assignment.

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

let puppies = 10;
puppies++;
console.log(puppies);

What are we doing to ‘puppies’ by using ++? What will the console log return?

A

Incrementing the number, adding one to it.

The console.log will return “11”

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

let droppedIceCreamCones = 150;
droppedIceCreamCones–;
console.log(droppedIceCreamCones);

What are we doing to ‘droppedIceCreamCones’ by using –? What will it return?

A

Decrementing it, taking one away

The console.log will return “149”

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

All integers is JS are ______ ______ numbers

A

Floating Point Numbers

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

What is another way to express:

b = 9 + b;

A

b += 9;

Plus-equals operator

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

What is another way to express:

a = a - 6;

A

a -= 6;

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

What is another way to express:

c = c * 10;

A

c *= 10;

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

What is another way to express:

a = a / 12 ;

A

a /= 12;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
let myFavoriteThings = 'Gaming\nKnitting\nCoding';
console.log(myFavoriteThings)

What does the ‘\n’ an example of, and what does it do?

A

<p>'\n' is an example of a <i>string escape sequence</i> and will start the section of the string following it on a new line. </p>

So for this example: 
console.log(myFavoriteThings) will return
"Gaming
Knitting
Coding" < -- each on their own line.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
const fullName = 'AdaLovelace';
const lastLetterOfName = fullName[fullName.length - 1];
console.log(lastLetterofName) 

What is this statement doing, and what will the return be?

A

This statement is finding the last index in the string by taking one away from the total length of the variable. Because JS starts counting at 0, taking one will dictate the last character.

It will return “e.”

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

How do we find out the length of a string?

Tip: This is a method

A

<p>By using the <b>.length</b> method</p>

Ex: 
let firstNameLength = 0; 
const firstName = 'Bartholomew'; 
firstNameLength = firstName.length; 
console.log(firstNameLength)

Will return: 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
const name = "Einstein"; 
let fourthLetterOfName = name[_];
console.log(fourthLetterOfName) 

What would we put into the square brackets to find the fourth index in the string (i.e. the fourth letter of Einstein’s name)?

Tip: Remember JS starts counting at 0!

A

3

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

What is an array?

A

An array is an object that allows us to group and store data as a single variable.

It contains multiple values, that can be of mixed data types, and can even be other arrays or objects.

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

How do we take a copy of an array?

A

by using […arrayName];

ex.

const names = ['Harry', 'Marshall', 'Alex'];
const myFavName = [...names];
console.log(myFavName);

Will return the list ‘Harry’ ‘Marshall’ ‘Alex’ in that order, and now other methods can be used to change it, without changing the original data set.

22
Q

What method do you use to add a new item or items to an array?

A

.push

Ex.
let animals = [‘birds’, ‘dogs’, ‘cats’];
animals.push(‘reptiles’)
console.log(animals);

will return - reptiles, birds, dogs, cats

23
Q

, >=, <= are all _____ Operators

A

They are all Comparison Operators

24
Q

What is === known as?

A

The Strict Equality Operator

25
Q

What is == known as?

A

The Loose Equality Operator

26
Q

True or False: Javascript automatically converts types of data as needed.

A

True

JS will automatically convert strings, numbers, and other primitive data types through a process known as Type Coercion.

27
Q

What are the 3 ways to write conditional code?

A

if/else statements
the ternary operator
switch statements

28
Q

&&, | | and ! are all _____ Operators

A

They are Logical Operators

29
Q

How is escaping performed?

A

Using a backslash before a ‘

Example:

console.log(‘She's in need of an escape!’);

30
Q

What is a falsy value?

A

A falsy value is a value that will automatically be converted to false in an if/else conditional

31
Q

undefined, null, 0, ‘ ‘ and NaN are all ____ values

A

They are falsy values

32
Q

What is a truthy value?

A

All values that are NOT falsy values

33
Q

When it comes to === and ==, what is the Best Practice operator to use?

A

It is best practice to use the strict equality operator, ===, because it helps avoid unexpected situations and bugs

34
Q

What is the difference between the loose equality operator (==) and the strict equality operator(===)?

A

The strict equality operator DOES NOT perform type coercion, but the loose equality operator DOES

35
Q

condition ? value if true : value if false

What is the above an example of?

A

Ternary Operator

36
Q

What are the 5 falsy values?

A
Null
Undefined 
0
''
NaN
37
Q
function doSomething(thisParam) {
    what is this space between curly brackets known as;
}
A

The space between curly brackets is known as the code block, in this case the function code block, or function block.

38
Q

The use of functions helps keep code DRY.

What does DRY mean?

A

DRY means Don’t Repeat Yourself.

Functions make it so we do not have to type the same code over and over again.

39
Q

What are functions?

A

Functions, simplistically, are blocks of code designed to perform a task

40
Q

What is a switch statement?

A

A switch statement is another way to write a conditional statement. It uses cases to determine outcome.

41
Q

What equality operator does a switch statement use?

A

A switch statement uses the strict operator!

This is important to note, because a strict comparison can only be true if the operands are of the same type.

42
Q

What is an array?

A

An array is a special variable that can hold more than one value.

43
Q

True or False: Arrays can contain different data types?

A

True, arrays can contain multiple values, that can be mixed between numbers, strings, etc.

44
Q

What is the most common way arrays are initialized?

A

The most common way of creating an array is using the Array Literal. Meaning using two square brackets to contain the array values:

= [ ];

45
Q

What does it mean when we say arrays are zero based?

A

An array is zero based - meaning that it starts counting the index at 0, rather than 1.

46
Q

What are Array Methods?

A

Array methods are special functions specific to arrays, like .pop( ), .push( ), and so on.

47
Q

Ternary Operator skeleton:

condition ? ____ clause : ____ clause;

A

condition ? TRUTHY clause : FALSY clause;

48
Q

In JS what is a method?

A

A method is a function specific to an object - like array methods .pop( ), .push( ) and so on.

49
Q

Why is the break; keyword NOT necessary in a switch statement IF a return is used?

A

The return immediately finishes the function, making the break keyword redundant in those cases.

If the return keyword is not used, a break is necessary.

50
Q

What is the difference between an EXPRESSION and STATEMENT?

A

An expression is a piece of code that results in a value.

A statement is a piece of code that may perform a function, but doesn’t not evaluate to a value.