1. Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Here we want to create a collection of values from the same type. Doing so with integers is not possible, because putting together several numbers in such a manner would just be saved as a number itself, we wouldn’t be able to retrieve the individual values. Doing it with integers is highly difficult, because a sequence of numbers becomes a string of text and retrieving the values requires heavy lifting.
2. What variable type can be used in order to solve the problem of storing multiple values?
This problem is solved using an array, where several values of the same type are stored in a single variable that can then be called back. It and is written as a list of values between square brackets, separated by commas.
3. What are properties in Javascript?
They are values associated with an object or array. They are defining characteristics such as the length, its maximum or the place, or index, an element is in an array.
4. Which values do not have properties?
Null and undefined.
5. How can we access properties in a value (two ways)?
The two main ways to access properties in JavaScript are with a dot and with square brackets. For example value.x or value[x]. Using value.x makes you access the property x of value. For example value.length gives you the length of value, value.color gives you the color of value. When using brackets, what is between the brackets is evaluated and uses the result, converted to a string as the property name.
6. What are methods?
Methods are a properties that contain a function. They are linked to a value of the array. For example, array.push(X) will push the value in parenthesis to the array. .toUpperCase will put a text in upper case.
7. What are objects?
Objects groups values into a single variable and those values can be of different types
8. What problem do objects solve that cannot be solved with other value types we've learned so far (such as integer, string, array, boolean etc)?
Objects can store values and have properties of different types, whereas other datatypes, including arrays, cannot.
9. How do you define an object?
They are declared using braces:
let day1 = {
squirrel: false,
events: ["work", "touched tree", "pizza", "running"]
};
Each property is separated by a coma. It is declared using a name ( for example squirrel), from its value separating it from its value (: false).
10. What can you say about the mutability of Javascript objects?
You can change the properties of objects, causing a single object value to have different content at different times. Comparing two different objects using == will give you false always because objects are different in JS. The objects are compared, not their values.
11. Why can't you add new properties to a string variable?
Adding new properties to a string variable would equate changing the string and strings are immutable in JS.
12. What are rest parameters?
Rest parameters tell a function to accept all arguments it is given, instead of a fixed set as we have seen up until now. It can also be used to spread out an array into a function call, letting the function operate on the entire array. It can also be used to spread an array into another array, as in
let words = [“never”, “fully”];
console.log([“will”, …words, “understand”]);
// → [“will”, “never”, “fully”, “understand”]
To use a rest parameter, use the three dots as above.
13. What is serialization and what is a use case of serialization of data?
Giving a flat description of the data. Doing also enables communication between different programs, something hard to do otherwise, as the objects we build in JS and their properties are stored in adresses of the memory.
14. What is JSON?
JavaScript Object Notation, it is a serialization format, a very popular data storage and communication format.
You can iterate over arrays using a special kind of for loop— for (let element of array) .
15. What are the differences between JSON and the way programmers write objects in plain Javascript?
In JSon properties have to be in double quotes, not in JS, and the expressions allowed are only simple data. no functions, bindings or computation is authorized. JS let’s you do all of that