PART ONE
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?
Integers and strings are simple values, the atoms of a data structures. They are immutable, canât be changed. In the weresquirrel example we would need to be able to put these values into a context with other data. We might also need to change these values. Also, we need to be able to store multiple values, namely a set of log entries that do not only consist of just numbers and strings but also a list of activities and a Boolean value that indicates whether J. transformed or not. Finally, we would need to group these entries into a single value and then put these grouped values into an array of log entries (objects).
2. What variable type can be used in order to solve the problem of storing multiple values?
Arrays. Arrays are variables with which we can store multiple/different values.
3. What are properties in Javascript?
A Javascript property is a characteristic of an object, often describing attributes associated with data structures.
4. Which values do not have properties?
The values ânullâ and âundefinedâ do not have properties.
5. How can we access properties in a value (two ways)?
With a dot (.) and with square brackets ([ ]). (value.x, value[x]
6. What are methods?
Methods are properties that contain functions. ( for example .toUpperCase, toLowerCase, .pop, .push)
7. What are objects?
Objects are standalone entities with an arbitrary collection of properties.
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 are variables that can contain multiple values in form of properties (and property values) and methods. Objects allow to group and modify values (within objects). Thatâs not possible with other, primitive value types such as integer, string, array etcâŚ
9. How do you define an object?
An object can be defined by using { } brackets to create an expression:
var = { key1: value1, key2: value2, âŚ}.
Quotations will need to be added if the propertyâs name is not a valid binding or number.
var = { key1: âvalue1â, key2: âvalue2â, âŚ}.
10. What can you say about the mutability of Javascript objects?
Whereas numbers, strings and Booleans are immutable, properties of objects can be changed, causing a single object value to have different content at different times.
PART TWO
1. Why canât you add new properties to a string variable?
Because the value types string, number and Boolean are not objects. If you try to set new properties on them, it doesnât actually store those properties. Such primitive values are immutable and cannot bre changed/modified.
2. What are rest parameters?
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic functions in Javascript. As such it is useful for a function that needs to operate on any number of arguments.
4. What is serialisation and what is a use case of serialisation of data?
Serialization is the process whereby an object or data structure is translated into a format suitable (it is converted into a flat description) for transferal over a network, or storage (e.g. in an array buffer or file format). In JS you can serialize an object to a JSON string by calling the function JSON:
5. What is JSON?
JSON is a popular serialization format and stands for Javascript Object Notation. It is an open standard file and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute-value pairs and array data types. It is widely used as a data storage and communication format on the Web, even in languages other than JS.
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
In JSON all property names have to be surrounded by double quotes, and only simple data expressions are allowed: no function calls, bindings, or anything that involves actual computation, comments are also not allowed. Other than that JSON looks similar to Javascriptâs way of writing arrays and objects.