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).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • How can you access a key’s value in an object?
A
  • There are two ways:
    - objectName.keyName
    - objectName["keyName"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • Name all the primitive types in JavaScript.
A
  • number, bigint, string, boolean, undefined, null, symbol
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 (**=)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • What are the arithmetic operators? Name some of them.
A
  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)
  • Increment (++)
  • Decrement (--)
  • Exponentiation (**)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 (!==)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • What are the logical operators? Name some of them.
A
  • And (&&)
  • Or (||)
  • Not (!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • What is the difference between for, for of and for 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  • What are the main parts of a function?
A
  • Parameters, the function body, and arguments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  • What is a method?
A
  • A method is a function that belongs to an object or a class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  • Name 3 builtin functions (and/or methods) regarding strings.
A
  • str.length
  • str.split()
  • str.slice()
  • Str.repeat()
  • Str.search()
  • Str.toUpperCase()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  • Name 3 builtin functions (and/or methods) regarding numbers.
A
  • num.toFixed()
  • num.toPrecision()
  • Nr.toString()
  • Number()
  • parseInt()
  • parseFloat()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  • What are the differences between for loops and forEach?
A
  • A for loop is a general-purpose loop for iterating over values multiple times.
  • forEach is a higher-order function used to iterate over elements of an array and execute a callback function on each element.
20
Q
  • What is the difference between JavaScript data structures and JSON data structures?
A
  • JavaScript data structures are in-memory representations of objects, arrays, strings, etc.
  • JSON data structures are string representations of data, used for data interchange.
21
Q
  • How do you create JavaScript data structure from a JSON file’s data?
A
import * as fs from "node:fs";
let dataStructure = JSON.parse(fs.readFileSync("fileName.json", "utf8"));
22
Q
  • What is the difference between JavaScript data structures and DOM (HTML document) data structures?
A
  • JavaScript data structures are used to store and manipulate data in memory.
  • DOM data structures represent the structure of HTML documents and allow manipulation of the document’s content.
23
Q
  • What are the steps of changing a HTML element’s content with JavaScript?
A
  • Get the element using getElementById or querySelector.
  • Use properties like innerHTML, textContent, or insertAdjacentHTML to modify the content.
24
Q
  • What is an event listener?
A
  • An event listener is a built-in function that waits for a specific event to occur on an element and triggers a callback function in response.
25
- What are the steps of changing a HTML element's content when the element clicked?
- Create an event listener using `addEventListener`. - Inside the event listener, modify the element's content using `innerHTML` or other properties.
26
- Inside a `click` event listener, how can you access the element that has been clicked?
- By using the event object passed to the event listener function, often referred to as `event` or `e`.
27
- What are the differences between `display: block` and `display: inline` CSS properties?
- `display: block` makes an element a block-level element, taking up the entire width of its parent and stacking vertically. - `display: inline` makes an element an inline-level element, allowing other elements to sit beside it on the same line.
28
- What are the differences between `position: relative` and `position: absolute` CSS properties?
- `position: relative` positions an element relative to its normal position. - `position: absolute` positions an element relative to its closest positioned ancestor.
29
- What is the box model, name the CSS properties connecting to it?
- The box model describes how elements are rendered in terms of their content, padding, border, and margin. - Related properties: `margin`, `padding`, `border`, `width`, `height`, `box-sizing`.
30
- What CSS properties affect font and text appearance?
- `color`, `font-size`, `font-weight`, `font-family`, `line-height`, `text-align`, `text-transform`.
31
- What are the steps of adding or removing a HTML element's class name?
- Adding: `element.classList.add("className")` - Removing: `element.classList.remove("className")`
32
- Is `null` an object or a primitive?
- It is a primitive value and represents the absence of any value.
33
- What is `undefined`?
- `undefined` is a special value indicating that a variable has been declared but hasn't been assigned a value.
34
- What does it mean that a data type is mutable and what does it mean that it is immutable? Mention some examples.
- Mutable data types can be changed after creation. Examples include arrays and objects. - Immutable data types cannot be changed after creation. Examples include strings and numbers. ``` let mutableArray = [1, 2, 3]; mutableArray[0] = 10; console.log(mutableArray); // Output: [10, 2, 3] ``` ``` let immutableString = "Hello"; immutableString[0] = "W"; // This won't change the string console.log(immutableString); // Output: "Hello" ``` ``` let immutableNumber = 42; immutableNumber = 99; // This reassigns the variable console.log(immutableNumber); // Output: 99 ```
35
- What does it mean that a data type is passed by value and what does it mean that it is passed by reference? Mention some examples.
- Passed by value means that a copy of the value is passed to a function. Primitives are passed by value. - Passed by reference means that a reference to the original value is passed to a function. Objects are passed by reference.
36
- When to use `var`, `let`, and `const`?
- Use `var` for legacy code or when you need function scope (not recommended in modern code). - Use `let` for variables that will be reassigned. - Use `const` for variables that won't be reassigned.
37
- What is hoisting?
- Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope during compilation.
38
- What are the advantages of using a version control system?(git)
- Version control helps track changes, collaborate effectively, manage project history, and revert to previous states.
39
- What’s the difference between Git and GitHub?
- Git is a version control system for tracking changes in code. - GitHub is a platform that provides hosting for Git repositories and additional collaboration features.
40
- What are remote repositories in Git?
- Remote repositories are versions of a project that are hosted on a different server.
41
- Why does a merge conflict occur?
- A merge conflict occurs when changes made in two different branches of a repository cannot be automatically merged.
42
- How do you run a JavaScript file in the terminal?
- Use the command: `node .js`
43
- How do you stop a running a command in the terminal?
- Press `Ctrl+C`
44
- How go you get the previous command in the terminal?
- Use the up arrow key or press `Ctrl+R`
45
- How do you got to the current directory's parent directory in the terminal?
- Use the command: `cd ..`