JS Course 1: Fundamental 5 Flashcards

1
Q

What is the difference between arrays and objects?

A

They both hold a list of values which are usually numbers and strings. The difference is how you access the items in an array and object, and how objects have a different system to access their properties.

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

What are the properties of an object?

A

The key is the name you refer to to access the content or value of the property.

The value is the name you refer to as the content of the property.

If you have the “key” or “name” of the property, you can access it to refer to the “value” or the “content.”

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

What is the “delete” keyword

A

The “delete” keyword is used to delete an object property. This keyword cannot be used with arrays, it will leave empty holes.

Example:

delete obj.propertyName

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

What are integer properties?

A

An integer property is a term that means a string can be converted to and from an integer, because when it’s transformed to an integer and back, it is the same.

“+49” is the number 49 and the string “49” while “1.2” is not.

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

How do integer properties work with objects?

A

Objects are sorted by integer properties be default! But, by using the “+49” syntax, you can sort the keys as if they were non-integer.

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

What are object literals/figure brackets?

A

Object literals/figure brackets refer to how you create objects.

Syntax:
const obj = {…};

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

What is dot notation?

A

Dot notation is a way to access a property name in an object (and smth else I don’t remember lol) like this:

obj.name

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

What are square brackets used for with objects?

A

Square brackets are another way you can access object property values. They are similar to dot notation, but have some other possible uses. Generally, they tend to be more complex than using dot notation.

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

What are the pros and cons of using square brackets?

A

Pros:
- You can use square brackets to access property names by surrounding the name in quotes inside the brackets: obj[“name”]
- You can utilizes spaces in square brackets too: obj[” name “]
-You can use brackets in an object literal (called computed properties)
- You can take on more complex expressions inside square brackets.

Cons:
- Text can get unnecessarily complex and unreadable, compared to dot notation. Most of the time, you’ll want to use dot notation.

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

What is the “in” operator?

A

The “in” operator if an object has a property.
The syntax is like this:

“propertyName”

in object.
This is a condition that will either return true or false.
The in operator excels at this when compared to using strict equality === to undefined to see if it exists or not.

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

What is the for…in loop?

A

The for…in loop is used to go through every key of an object. The syntax is f

or(key in object)

with the body code proceeding.

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

What does the isEmpty() method do?

A

This method is used on strings to see if they are empty. This method proceeds the string (assigned to a variable of sorts) to see if it’s empty and returns a boolean value.

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

What does the “this” keyword do in reference to objects?

A

The “this” keyword refers to the current object the code is being written inside. This is how you can refer to other properties inside other properties of an object.

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

What is an Object Constructor?

A

Object constructors are used to create objects (plural.) If you want to work with multiple objects, you simply cannot declare objects by object literals all the time, so you can use object constructors that can be run to create several items with different, or the same, properties!

Think of object constructors like functions where if you call upon the name, the action is done, in this case creating an object.

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

What does the command console.table() do?

A

This command creates a table in the console (and apparently in the browser sometimes?) of an array/object you call inside the parentheses.

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

What does is the str.localcompare string method?

A

“localecompare” compares letters by their codes by default. This is very useful when sorting names that may have different characters outside of English.

For many alphabets, it’s better to use the str.localeCompare method to correctly sort letters such as Ö.