JavaScript Quirks Flashcards

(4 cards)

1
Q

What does the “dot” operator do? Code example:

const buttons = optionsContainer.querySelectorAll("button");

A

In JavaScript, the dot operator (.) is used to access properties and methods of objects.
It’s essentially how you “drill down” into an object to reach specific data or behavior. hink of it like this:

The dot means “of”.
So:
optionsContainer.querySelectorAll → “the querySelectorAll method of optionsContainer”.

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

Does querySelectorAll() need the dot before the class name?

A

Yes

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

Does getElementsByClassName need the dot before the class name?

A

No

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

What’s the difference between
logos.forEach(logo => ()); and logos.forEach(logo => {});

A

() => () → Implicit return.
Used for single-line expressions where you immediately return a value.
Example:
const squares = nums.map(n => n * n);

() => {} → Block body.
Used for multiple statements. You must use return explicitly if you want to return something.
Example:
const squares = nums.map(n => {
const result = n * n;
return result;
});

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