Data Structures (Arrays and Objects)
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?
We cannot easily access specific parts of strings or integers. Jacques needs to be able to store multiple values in a data structure. In this way he can keep track of data to determine which factors are causing the transformation to occur.
What variable type can be used in order to solve the problem of storing multiple values?
Array
What are properties in Javascript?
Properties are characteristics of a value. For example, myString.length.
Length is the property of the value of mystring.
Which values do not have properties?
Null & Undefined
How can we access properties in a value (two ways)?
. // value.x
and
[] // value[x]
What are methods?
Properties that contain functions are generally called methods.
They are accessed with the (.)
let myArray = [1, 2, 3];
myArray.push(4);
What are objects?
Objects are an abitraty collection of properties.
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 hold values of different datatypes.
They allow us to group a collection of different types of data into one object.
How do you define an object?
You define an object using braces as an expression. Inside the braces, there is a list of properties separated by commas. Each property has a name followed by a colon and a value.
let car = {
wheels: 4,
driven: false,
speed: 150,
};
What can you say about the mutability of Javascript objects?
Unlike the data type of strings, objects enable for objects to be changed.
Object values can be modified causing a single object value to have different content at different times.
SECOND PART:
Why canât you add new properties to a string variable?
Strings are not an object. They do not store properties. They are immutable and cannot be changed.
What are rest parameters?
the rest parameter is bound to an array containing all further arguments.
Rest parameters enable for a function to accept any number of arguments. Additionally, the rest parameter is bound to an array containing all further arguments. To create a rest parameters, they are denoted by three dots prior to the last parameter
What is serialisation and what is a use case of serialisation of data?
Serialisation is the conversion of saved data into a flat description. This enables the flexibility for the file to transfer within a computer and network easily.
What is JSON?
JSON (pronounced âJasonâ), which stands for JavaScript Object Notation is a serialization format. It a widely used data storage and communication format on the Web, even in languages other than JavaScript.
What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON looks similar to JavaScriptâs way of writing arrays and objects, with a few restrictions. 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. Also comments are not allowed in JSON.