Data Types Flashcards

1
Q

What is a primitive data type?

A

a basic data type that is not an object and has no methods or properties of its own

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

Name the six primitive data types. S,N,B,U,N,S

A

String, Number, Boolean, Undefined, Null, Symbol

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

What does null mean?

A

The absence of a value. A deliberate non-value, a variable intentionally empty.

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

What is undefined?

A

A variable that has not been assigned a value or a function that does not return anything.

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

Give an example of an undefined variable

A

let name;

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

Give an example of a null variable

A

let n = null;

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

Give three examples of when you might want to return a null value

A

1) When initialising a variable that does not yet have a a value.
let username = null;

2) Clearing the value of a variable. username = null;

3) If a function cannot return a value - i.e no user id in database, then option to return ‘null’.
function getUser(id) {
if (id === 0) {
return { name: ‘John’ };
} else {
return null;
}
}

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

What code can we write in console.log to find out the type of a variable? e.g let age = 5;

A

console.log*typeof age) - with the space.

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

What is an object?

A

data type that represents a collection of related data or functionality. An object can be thought of as a container for properties and methods

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

How can we create an object without any properties or values yet?

A

let emptyObj = new Object();

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

What is an object ‘literal’ from this code let person = { name: ‘John’, age: 30 };

A

{ name: ‘John’, age: 30 };
It is called a literal because it is a notation that represents the properties and values of the object directly in the code, as opposed to creating an object using a constructor function.

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

Create an empty object using an object literal

A

let emObj = {};

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

let person = { name: ‘John’, age: 30 }; How can I access age through dot notation?

A

Console.log(person.age);

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

What is a primitive value vs reference value?

A

const num1 = 6;
const num2 = num1;

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

Arrays - let shoppingItems = [“apple”, “dogFood”, “milk”];

What method can I use to add a new item onto the array? i.e “Oranges”

A

shoppingItems.push(“Oranges”);

MEMORY AID = Imagine furiously pushing an array that it makes the last one birth a baby value.

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

Arrays - let shoppingItems = [“apple”, “dogFood”, “milk”];

What method can I use to add a new item onto the beginning array? i.e “Oranges”

A

let shoppingItems.unshift(“Oranges”);

MEMORY AID = Imagine a bus, where it’s super squished and someone wants to squeeze in when doors open. They have to ‘unshift’ to let them on. Shift- means move - so unshift means add.

17
Q

Arrays - let shoppingItems = [“apple”, “dogFood”, “milk”];

What method can I use to remove an item from the end of an array - i.e “Milk”

How is this method different from the others?

A

let shoppingItems.pop()

-It does not require a value since you are removing it.

18
Q

Arrays - let shoppingItems = [“apple”, “dogFood”, “milk”];

What method can I use to remove an item from the beginning of an array? i.e “apple”

How can you remember this?

A

shoppingItems.shift(shoppingItems);

Imagine you start a ‘shift’ when you BEGIN work.

Shift - remove from start of array.
Unshift - add to start of array.

19
Q

How can I access and change the final element of this array?

let arr1 = [1,2,3,4,5]);

A

arr1[arr1.length-1] = 8;

20
Q

const fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’];

fruits.splice(1, 2);

console.log(fruits); // output?

Does splice create a new array or not?

A

fruits = [“apple”, “date”];

not a new array- modifies original

21
Q

What is the syntax of splice?

const num = [1,2,3,4,5];

splice(?, ?);

A

splice(indexStart, deleteCount);

22
Q

Does splice create a new array?

A

No modifies original

23
Q

crea

A