JavaScript Data Types (Booleans, Objects, Arrays) Flashcards

... (20 cards)

1
Q

What is a JavaScript boolean?

A

A data type representing a truth value: true or false.

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

Give an example of a use case for booleans.

A

Conditional logic (e.g., if statements), flags/switches, comparisons in loops.

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

How do you declare a boolean variable in JavaScript?

A

let isLoggedIn = true; or let isAdult = false.

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

What are the ‘falsy’ values in JavaScript?

A

0, “” (empty string), null, undefined, NaN.

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

What is a JavaScript object?

A

A collection of properties, where each property has a key (name) and a value.

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

Give an example of a use case for objects.

A

Representing real-world entities (users, products), storing configurations, organizing code.

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

How do you create an object in JavaScript?

A

Using curly braces {}: let person = { name: “Alice”, age: 30 };

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

How do you access a property in an object using dot notation?

A

objectName.propertyName (e.g., person.name).

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

How do you access a property in an object using bracket notation?

A

objectName[“propertyName”] (e.g., person[“age”]) - Useful for variable keys.

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

What is a method in an object?

A

A function defined as a property of an object. It can be called using object.methodName().

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

What does this refer to inside an object’s method?

A

The object itself.

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

How do you add a new property to an existing object?

A

objectName.newProperty = value.

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

How do you delete a property from an object?

A

delete objectName.propertyName.

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

What is a JavaScript array?

A

An ordered list of values.

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

Give an example of a use case for arrays.

A

Storing lists of items, representing collections of data, performing operations on sequences.

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

How do you create an array in JavaScript?

A

Using square brackets []: let colors = [“red”, “green”, “blue”];

17
Q

How do you access an element in an array?

A

Using its index (starting from 0): arrayName[index] (e.g., colors[0]).

18
Q

How do you find the number of elements in an array?

A

Using the length property: arrayName.length.

19
Q

Name three common array methods for adding/removing elements.

A

push() (add to end), pop() (remove from end), shift() (remove from beginning), unshift() (add to beginning).

20
Q

Explain the difference between slice() and splice() array methods.

A

slice() creates a new array containing a portion of the original. splice() modifies the original array by removing or replacing elements.