PB Flashcards
1
Q
What are the differences between objects
and arrays
? What is the purpose of the object
and what is the purpose of the array
?
A
- An object can store multiple properties with key names, while an array can store a list of items that are usually of the same type (e.g., all numbers or all strings).
- You can access an object’s property using the property’s key name, while you access an array’s element using its index.
- Objects are typically used to store properties that describe something, like the attributes of a book (name, author, price, etc.).
- Arrays are commonly used to store lists of data, like a group of ages or a collection of objects (e.g., books).
2
Q
- How can you access a key’s value in an object?
A
- There are two ways:
-objectName.keyName
-objectName["keyName"]
3
Q
- How can you access the first and the last item of an array? (JS)
A
- First element:
arrayName[0]
- Last element:
arrayName[arrayName.length - 1]
4
Q
- Name all the primitive types in JavaScript.
A
- number, bigint, string, boolean, undefined, null, symbol
5
Q
- What are the assignment operators? Name some of them.
A
- Assignment (
=
) - Addition assignment (
+=
) - Subtraction assignment (
-=
) - Multiplication assignment (
*=
) - Division assignment (
/=
) - Modulus assignment (
%=
) - Exponentiation assignment (
**=
)
6
Q
- What are the arithmetic operators? Name some of them.
A
- Addition (
+
) - Subtraction (
-
) - Multiplication (
*
) - Division (
/
) - Modulus (
%
) - Increment (
++
) - Decrement (
--
) - Exponentiation (
**
)
7
Q
- What are the comparison operators? Name some of them.(JS)
A
- Equal to (
==
) - Strict equal to (
===
) - Less than (
<
) - Greater than (
>
) - Less than or equal to (
<=
) - Greater than or equal to (
>=
) - Not equal (
!=
) - Not equal value or type (
!==
)
8
Q
- What are the logical operators? Name some of them.
A
- And (
&&
) - Or (
||
) - Not (
!
)
9
Q
- What is the difference between
for
,for of
andfor in
?
A
-
for
is a loop used to execute a block of code a certain number of times. -
for...of
loops through the values of iterable objects like arrays, strings, sets, and maps. -
for...in
loops through the properties of an object.
10
Q
- How do you find the average of values in an array if you can’t use any built-in functions or methods?
A
let sum = 0; for (let value of array) { sum += value; } let average = sum / array.length;
11
Q
- What are the main parts of a function?
A
- Parameters, the function body, and arguments.
12
Q
- What is the difference between parameters and arguments?
A
- Parameters are placeholders in the function’s declaration, while arguments are the actual values passed to the function when it’s called.
13
Q
- What are the differences between function expression and function statement?
A
- Function expression:
var foo = function() {...};
- Function declaration:
function foo() {...};
- Function declarations are hoisted and can be used before their declaration. Function expressions are not hoisted and can’t be used before their declaration.
14
Q
- What is a method?
A
- A method is a function that belongs to an object or a class.
15
Q
- Name 3 builtin functions (and/or methods) regarding strings.
A
str.length
str.split()
str.slice()
Str.repeat()
Str.search()
Str.toUpperCase()
16
Q
- Name 3 builtin functions (and/or methods) regarding arrays.(JavaScript)
A
arr.length
arr.slice()
arr.push()
Arr.pop()
Arr.splice()
Arr.join()
Arr.indexOf()
17
Q
- Name 3 builtin functions (and/or methods) regarding numbers.
A
num.toFixed()
num.toPrecision()
Nr.toString()
Number()
parseInt()
parseFloat()
18
Q
- What is a callback function?
A
- A callback function is a function passed as an argument to another function and is executed after the completion of that function.