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?
For keeping a journal and collecting data in an organized manner for each day would be a difficult task with strings and integers alone.
2. What variable type can be used in order to solve the problem of storing multiple values?
Arrays can be used to store a collection of values in a single value.
3. What are properties in Javascript?
Most values have properties that can be called and perform different tasks on the stored values.
4. Which values do not have properties?
Null and undefined.
5. How can we access properties in a value (two ways)?
Dot notation: Math.max();
or
Call by name: Math"max";
6. What are methods?
Methods are properties of a value that can perform different useful functions. For example in case of an array, if we want to remove the last element of the array: array.pop();
7. What are objects?
Objects are value pairs stored in a single value.
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 any type of value pairs and these can be later accessed. Objects can store arrays with booleans etcâŚ
9. How do you define an object?
let ivanOnTech {
days: [ "monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday" , "sunday" ];
time: [ "8 am central european time" , "11:30AM, atomic weekend time"];
person: Ivan;
}
10. What can you say about the mutability of Javascript objects?
Properties of objects are mutable. An object can have different values for a property at different times.
SECOND PART:
1. Why canât you add new properties to a string variable?
Immutability of the string variable prevents it, but also why would you want to do that? Objects are a more flexible datatype where properties can be added.
2. What are rest parameters?
With the three dot notation it is possible to call all the values of an array like:
let days = ["monday" , "tuesday"]
console.log(...days + " wednesday, thursday, friday, sunday, saturday")
//m o n d a y , t u e s d a y w e d n e s d a y , t h u r s d a y , f r i d a y , s u n d a y , s a t u r d a y
Or to make a function or method accept all arguments it is given without setting up a variable.
function addEm (...numbah) {
let result = 0;
for (let number of numbah) {
result += number;
}
return result;
}
console.log(addEm(2,2,2,2,2,2,2))
//14
3. (Feel free to skip the sub-chapter of Math object and Destructing)
4. What is serialisation and what is a use case of serialisation of data?
As far as I understood, serialized data is basically a standard for data structures. It looks like an object, but it is not really connected to Javascript, other programs can also read the value pairs.
5. What is JSON?
The abbreviation stands for Javascript Object Notation.
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON objects hold purely the data, functions or computations are not valid. Every property has to be in double quotes.