Data Structures (Arrays and Objects) - Reading Assignment


#41

What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
He was trying to determine what was causing him turn into a weresquirrel. To do this he had to keep a daily log of everything he did on a given day and whether he changed form. This problem could not be resolved by single-value strings or integers. It required objects.

What data type can be used in order to solve the problem of storing multiple values?
arrays or objects

What are properties in Javascript?
Properties are the values associated with a JavaScript object.

Which values do not have properties?
undefined, null

How can we access properties in a value (two ways)?
value.property and value[property]

What are methods?
Methods are actions that can be performed on objects.

What are objects?
A collection of properties and methods usually organized on a particular topic.

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)?
Problems that require data structures with multiple related methods and properties.

How do you define an object?
var person = {firstName:“John”, lastName:“Doe”, age:50, eyeColor:“blue”};

What can you say about the mutability of Javascript objects?
Object values are mutable. Values such as numbers, strings, and Booleans, are all immutable


#42

What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?

  • The need for a dataset that can store multiple different value types

What variable type can be used in order to solve the problem of storing multiple values?

  • Arrays

What are properties in JavaScript?

  • Characteristics of values in the data structure

Which values do not have properties?

  • Null and undefined

How can we access properties in a value (two ways)?

  • Square brackets and period(or dot)

What are methods?

  • Properties that hold a function

What are objects?

  • An arbitrary collection of values

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)?

  • Flexibility, objects can store different kinds of values

How do you define an object?

  • Defined as the binding and its value in braces

What can you say about the mutability of JavaScript objects?

  • Object values can be modified

Why can’t you add new properties to a string variable?

  • Strings are immutable and cannot be changed

What are rest parameters?

  • Parameter syntax that allows us to represent an indefinite number of arguments as an array

What is serialization and what is a use case of serialization of data?

  • The conversion of saved data into a flat description, enabling transfer within a computer and network.

What is JSON?

  • JavaScript Object Notation which is widely used as a data storage and communication format on the web.

What are the differences between JSON and the way programmers write objects in plain JavaScript?

  • In JSON, all property names must be surrounded by double quotes and only simple expressions are allowed.

#43

Arrays and Objects:

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?

Solving the weresquirrel problem requires to keep track of a sequence of data. It is not ideal to deal with sequences using simply strings, integers or booleans.

2. What variable type can be used in order to solve the problem of storing multiple values?

We can use arrays.

3. What are properties in Javascript?

Properties of an object in Javascript are parameters associated to those objects that can be retrieved using some methods.

4. Which values do not have properties?

‘null’ and ‘undefined’ do not have any properties in Javascript.

5. How can we access properties in a value (two ways)?

Properties in a value can be accessed using square brackets [] or a dot expression ‘.’.

6. What are methods?

Methods are properties that contain functions.

7. What are objects?

Objects are collections of properties of an arbitrary nature.

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 allow us to group in a single value arbitrary collections of properties which provide flexibility in creating building blocks to solve a problem.

9. How do you define an object?

The syntax used to define an object is

let objectName = {
keyOne: valueOne,
keyTwo: valueTwo,

};

10. What can you say about the mutability of Javascript objects?

Strings, integers, etc are immutable meaning that their properties cannot be changed. On the other hand objects are mutable which means their properties can be different at different times in the code.

Strings and their properties:

1. Why can’t you add new properties to a string variable?

A string variable is immutable thus its properties cannot be changed.

2. What are rest parameters?

A rest parameter allows to pass an indefinite number of arguments to a function.

3. (Feel free to skip the sub-chapter of Math object and Destructing)

SKIPPED

4. What is serialisation and what is a use case of serialisation of data?

Serialisation is the process of converting the data that is stored by addresses into the computer memory to a flat structure. A use case of serialisation is sending data over a network.

5. What is JSON?

JSON stands for JavaScript Object Notation and is a format of serialisation.

6. What are the differences between JSON and the way programmers write objects in plain Javascript?

The main differences between JSON and objects in JavaScript are that JSON property names must be in between double quotes and only simple data (no functions) can be passed as values.


#44

Why can’t you add new properties to a string variable?
Values of type string are not objects

What are rest parameters?
I like to think of themm as “the rest” of the parameters.
…parameters in a function parameter list or a funtion call allows a series of values to be entered, put into an array, and used appropriately.

What is serialisation and what is a use case of serialisation of data?
serialization is the converting of JS data in for instance, objects and variables, into a flat (text) file. It is used to send data from server to browser.

What is JSON?
Javascript object notation… a protocol for sending and receiving JS data.

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.


#45

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 need to hold multiple values. That would not be possible with string or integer variable types.
What variable type can be used in order to solve the problem of storing multiple values?
objects and arrays
What are properties in Javascript?
Properties are expressions that access a property of some value
Which values do not have properties?
null and undefinied
How can we access properties in a value (two ways)?
by using a dot or square brackets
value.i
value[“i”]
What are methods?
properties that contain functions
x.push(3);
What are objects?
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)?
we can group together different types of data
How do you define an object?
objects are defined by {}
let x = {events: [“school”, “work”, “shopping”] };
What can you say about the mutability of Javascript objects?
values in string and integer datatypes can’t be changeable. otherwise in objects we can change values.

SECOND PART:

1.Why can’t you add new properties to a string variable?
string variables are immutable. If we want to add new properties, we need to use objects

2.What are rest parameters?
Rest parameters allow a function to accept any number of arguments. To write such a function, we use three dots (…) before the function’s last parameter

3.(Feel free to skip the sub-chapter of Math object and Destructing)
skipped
4.What is serialisation and what is a use case of serialisation of data?
Serialization is the process of converting data structures or an object state into a format that can be stored or sent.
5.What is JSON?
JavaScript Object Notation. it is a popular serialization format.
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 not allowed in JSON.


#46

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?
We have to store and process sequence of data and for that simple variable types are just not suitable.
2. What variable type can be used in order to solve the problem of storing multiple values?
We can use arrays.
3. What are properties in Javascript?
Properties are certain characteristics associated with values.
4. Which values do not have properties?
null and undefined have no properties.
5. How can we access properties in a value (two ways)?
with a dot or square brackets.
6. What are methods?
Methods are functions that are accessible as properties.
7. What are objects?
Object is a collection of properties and values.
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)?
We can change a value or a property in an object. We can not do that with simple types. It can also store values of different types.
9. How do you define an object?
let object1={ name: “Bob”, age: 27}
10. What can you say about the mutability of Javascript objects?
They are mutable which means properties and values can be changed.

SECOND PART:

1. Why can’t you add new properties to a string variable?
Simple types are immutable.
2. What are rest parameters?
Rest parameters allow any number of parameters.
3. (Feel free to skip the sub-chapter of Math object and Destructing)
Done.
4. What is serialisation and what is a use case of serialisation of data?
Serialization is a way to ‘flatten’ the data to be serialized which is a fancy word for ready to transport over network and that’s the use case.
5. What is JSON?
JSON is a standard to use to serialize data in Javascript. It’s widely used elsewhere not just JS.
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON object has to use double quotes for properties and values unless value is a number. We can not serialize functions and complex expressions that require calculation.


#47
  1. It’s helpful to have a means to store both strings or integers in the same container. The way to do that is to use an object. It can also contain booleans. Any of the values inside of it can be called with an object key. Objects allow storing different values in one value itself that can be easily called or altered.

  2. Arrays store multiple values.

  3. Properties are specific features of a value. Two examples would be .length which gives the length of a string or array. In the case of .max the property would be the highest number from a specific list.

  4. Two values that do not have properties are null and undefined.

  5. Two ways would be dot notation like value.x or with square brackets, for example: value[x].

  6. Methods are properties of values that can be called on them. In the case of arrays, .push is a method that pushes a new value to the end of the array. Another method would be .toUpperCase that can be used on a string to make all the letters uppercase.

  7. An object is an arbitrary collection of properties. It allows a user to place a flexible, wide option of values into one value itself. With something like let testObject = { name: “test”, age: 0, array: [1,2,3], final: true} many different values can be stored and called with ease. It doesn’t have quite the same limitations as just using an array.

  8. Object values are not immutable. In other words, they can be changed so an object value has different content at different times.

  9. Objects are defined as follows: let answerObject = { answer: “text”}.

  10. JavaScript objects are mutable, unlike other values. A string “cat” cannot be changed to “rat” would be one example. Objects are more independent and can stand alone so having the same value in an object would not show as being equal to a different object.

  11. Strings are immutable and wouldn’t recognize trying to add a property with dot notation the same way as it would be done with an object.

  12. A rest parameter use three dots, … , to signify the usage of more than just one value.

  13. Serialization is the conversion of data to a flat state where it can be more easily transferred as compared to sending the whole location of the data in memory. JSON is an instance of serialization.

  14. JSON is JavaScript Object Notation. It’s a way to transfer data in a format very similar to an object that can be parsed to get full data out of a previously condensed format.

  15. When writing JSON all property names are in quotes. There are also no comments or anything that requires higher level computing like functions or bindings.


#48

PART 1

1. When we want to store or list a large data, strings and numbers are not suitable as it is inefficient to extract data from these kinds of variable types.

2. An array can store multiple values.

3. Properties in javascript are a type of expression that can access specific information about its associated value.

4. Null and undefined do not have properties.

5. Properties in a value can be accessed in two ways:

i) Using a dot (value.x)
ii) Using square brackets (value[x])

6. Methods are special properties that have a function associated with a value, e.g. sequence.push and sequence.pop

7. Objects are a collection of listed properties assigned to a value.

8. The unique feature of objects is that one single value can store different types of properties, whether they are strings, numbers or Booleans.

9. Use braces { } to define an object. Inside the braces, one can list properties. Each property has a colon followed by a value. Properties are separated by using a comma.

10. There are some value types in Javascript (e.g. strings, numbers, Booleans), which are considered immutable. This means it is impossible to change the value of these types. The value always remains the same.

Comparatively, object values are mutable. One can change the properties of an object value, so that it has different content at different times. It is important to note that if two different object values have the same properties, they are not considered equal or related. However, if two different references bind to the same object value, they share an identity.

PART 2

1. One cannot add new properties to a string variable because strings are not considered objects, so it will not store a property. However, there do exist in-built properties for strings called methods, such as ‘slice’ and ‘indexOf’.

2. Rest parameters are represented by three dots and are placed before a function’s last parameter. The three dot notation implies that the function is bound to an array containing all further (indefinite) arguments.

3. The memory in a computer stores addresses - where objects and arrays hold their contents. **Serialisation is a way in which to save, access and send these memory addresses as text. A use case of serialisation of data is when a browser communicates to a server and vice versa. Javascript objects can be converted into text in JSON format (using JSON.stringify) and sent to the server. The server can send data in JSON format to the browser, which can be converted to Javascript objects (using JSON.parse).

4. JSON stands for Javascript Object Notation. It is a popular serialisation format used on the web for storing and exchanging data.

5. Differences between JSON and the way programmers write objects in Javascript:
• In JSON, property names must be surrounded by “double quotes”.
• In JSON, only simple data expressions that involve no computation are allowed, i.e. no bindings and no functions.
• In JSON, no comments are allowed.


#49
  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?
    Datatypes as “strings & integers” are primitive types of value, that don’t allow us the flexibility of storing and manipulating values as we can do, for ex., with objects. In the weresquirrel problem, our friend definitely needs an organised datastructure in order to be capable of manipulating values in time.

  2. What variable type can be used in order to solve the problem of storing multiple values?
    We can use array type variable in order to store multiple strings and integers.

  3. What are properties in Javascript?
    We all know the majority of Javascript values can have properties attached to them. Properties are seen as what kind of characteristic a specific value holds in a datastructure. Since Javascript is also an Object Oriented Programming Language, objects in Javascript usually hold properties

  4. Which values do not have properties?
    Exceptions to JavaScript values that do not have properties are the values null and undefined.

  5. How can we access properties in a value (two ways)?
    Properties are the values associated with a JavaScript object.
    A JavaScript object is a collection of unordered properties.
    Properties can usually be changed, added, and deleted, but some are read only.
    We can access properties in a value in 2 ways:
    • Through a dot and the literal name of the property:
    (objectName.property // person.age)
    • By using square brackets:
    (objectName[“property”] // person[“age”])

  6. What are methods?
    A method is an action that we can perform with our object. An object can hold properties, that can hold methods, that can act on the value they belong to.

  7. What are objects?
    Basically almost everything in JavaScript is an object. All JavaScript values, except primitives, are objects.
    • Dates are always objects
    • Maths are always objects
    • Regular expressions are always objects
    • Arrays are always objects
    • Functions are always objects
    • Objects are always objects

  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 special because they allow us to hold and change the state of as many different datatypes as we want. This cannot be done with values as integer, string, array and boolean cause these are primitive values.

  9. How do you define an object?
    Objects are data structures that are created using braces to contain a list key/value pairs separated by a comma.

  10. What can you say about the mutability of Javascript objects?
    With Javascript we have the possibility to change the values inside an object, whereas with primitive datatypes we cannot do this, cause they are immutable.

SECOND PART:

  1. Why can’t you add new properties to a string variable?
    A string is not an object but a primitive type, so it is immutable.

  2. What are rest parameters?
    The rest operator is the opposite of the spread operator.
    A spread operator, takes a all the elements inside an array and literally spreads/expands them into individual elements.
    On the other hand a rest operator collects multiple elements(arguments) and condenses into a single array element.
    They both work with 3 dots in front of their name.

  3. What is serialisation and what is a use case of serialisation of data?
    Serializing Objects. Object serialization is the process of converting an object’s state to a string from which it can later be restored. ECMAScript 5 provides native functions JSON.stringify() and JSON.parse() to serialize and restore JavaScriptobjects. These functions use the JSON data interchange format.

  4. What is JSON?
    JavaScript Object Notation is a widely used standard for data storage and communication on the web.

  5. What are the differences between JSON and the way programmers write objects in plain Javascript?
    JSON looks the almost the same as plain JavaScript but with the following restrinctions:
    . All property names must be surrounded by double quotes, only simple data expressions are allowed.
    . No function calls
    . No bindings
    . Anything that involves actual computation
    . Comments are not allowed


#50
  1. Data Structures
    2.An Array
  2. Properties define some characteristics of a value
  3. Null and Undefined
  4. by using a dot and name of the property or square brackets
  5. Methods are properties that hold function values
  6. Objects are data structures that are capable of containing an arbitrary collection of properties.
  7. Objects can hold as many data types as we need.
  8. Just like any other variable, with the value being a list inside braces
  9. The values contained in Javascript objects can be changed

1.String values are not objects
2. Rest parameters accept any number of arguments
3. (…)
4. Serialization is the process of converting data structures or a object state into a format that can be stored. It is used to save data in a file or send it to another computer over the network.
5. JSON (JavaScript Object Notation) is a popular serialization format.
6. Only simple data expressions are allowed and all property names have to be surrounded by double quotes.


#51

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?

To save more complex data sets a hand full of variables maybe not enough. So we need some layer on top to structure them.

What variable type can be used in order to solve the problem of storing multiple values?

An Array can be used to store multiple values.

What are properties in Javascript?

It allows to access properties of a certain value. like “hello”.length

Which values do not have properties?

null and undefined do have no properties.

How can we access properties in a value (two ways)?

The properties can be accessed with the .dot notation.
The name of the property can be accessed through indexing [0].

What are methods?

Properties like “hello”.length contain a function and that function is called a method. The method .toUpperCase for example returns “HELLO”

What are objects?

With an object we can store multiple values as properties of that object

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 easy be manipulated

How do you define an object?

let price = { bid: 5882.5, ask: 5883.5 }

What can you say about the mutability of Javascript objects?

null


#52

Why can’t you add new properties to a string variable?

A String variable is i basic variable type not a object.

What are rest parameters?

with the rest parameter a function can accepts any number of arguments and stores them in a array.

(Feel free to skip the sub-chapter of Math object and Destructing)

Remmber to read it again!

What is serialisation and what is a use case of serialisation of data?

serialization is used to flatten out the structure of the data. This allows us to store specific data in a easy readable format. We do not store the memory address of something, instead we save the actual values at these addresses.

What is JSON?

It’s a format used for data description used mostly for storage and communication within the web.

What are the differences between JSON and the way programmers write objects in plain Javascript?

It is pretty similar to define a object but there are no functions and methods that can be used. There is no logic within JSON.


#53

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?
It consist of number of data which is of any type string, integers, boolean
2. What variable type can be used in order to solve the problem of storing multiple values?
An array can be used for storing multiple values
3. What are properties in Javascript?
Properties gives the added knowledge of a value
4. Which values do not have properties?
Undefined and null
5. How can we access properties in a value (two ways)?
By using dot and second by using square brackets
6. What are methods?
Properties which performs some desired action over the value are called methods. properties that has functions are methods.
7. What are objects?
Objects are a combination of data with multiple 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)?
It can store data with more than one type
9. How do you define an object?
Multiple data of any type store under one name is an object
10. What can you say about the mutability of Javascript objects?
Mutability is a characteristic of objects with tells about the ability to change the property of values
11. Why can’t you add new properties to a string variable?
Other than objects no new property can be added or deleted from a data of any type
12. What are rest parameters?
Undefined number of parameters are called rest parameters
13. What is serialisation and what is a use case of serialisation of data?
Serialisation means converting the data which is pointing to an address to a simplier description which then can be send over the network
14. What is JSON?
JSON is a serialization format which stands for javascript object notation
15. What are the differences between JSON and the way programmers write objects in plain Javascript?
In JSON, property needs to be put in double quotes and no function call, binding or comments are allowed.


#54
  1. The weresquirrel shows us that some problems require grouped data, each related to one another, but not necessarily of the same data type. As such, simple variables would not suffice as they can only hold data of one type.
  2. Objects may be used to store data of different values.
  3. Properties define some characteristic about the values in a data structure.
  4. null and undefined do not have properties
  5. Properties may be accessed as follows: value.prop or value[“prop”]
  6. Methods are properties that hold function values. They are special kinds of functions that only work on the value they belong to.
  7. Objects provide ways to group several values into a single value.
  8. Objects allow us to store multiple data types in a single value, as opposed to a single kind. They are useful for grouping related items together.
  9. Objects are defined in a similar manner to any other variable, with their value(s) being contained in braces {}.
  10. Javascript objects are mutable, meaning their values can be changed.

Second Part:

  1. String variables are immutable, and therefore it’s properties cannot be changed.
  2. The rest parameter is represented by three dots (…) They allow us to represent an indefinite number of arguments as an array.
  3. Serialization is combining data stored in memory into a flat representation of what that data is.
  4. JSON or JavaScript Object Notation is widely used as a data storage and communication format on the Web, even in languages other than JavaScript.
  5. 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 in JSON.

#55

The weresquirrel using variable types such as strings and integers cannot be solved due to the challenge was to find a correlation between the events and the squirrel turns.

EG: storing data in sequence like Array would solved his problem while any other types does not stored value in order.

Array

3.1 Properties are the values associated with a JavaScript object.
3.2 A JavaScript object is a collection of unordered properties.
3.3 Properties can usually be changed, added, and deleted, but some are read-only.

For example:
myString.length // This is an expression that accesses a property of some value. In the first case,
we access the length property of the value in myString_

null and undefined

The two main ways to access properties in JavaScript are with a dot and with
square brackets.

Properties that contain functions are generally called methods.

For example “toUpperCase" or xxx.toUpperCase(); is a method of a string

Objects provide ways to group several values into a single value. E.G if you created car object, a car object can stored all different datatypes in a single variable.

Firstly, values of type string, number, and Boolean are not objects, and if you try to set new properties on them, it doesn’t actually store those properties. As such values are immutable and cannot be changed.

Objects work differently. You can change their properties, causing a single object value to have different content at different times.

One way to create an object is by using braces as an expression.

let descriptions = {
   work: "Went to work",
   "touched tree": "Touched a tree"
};

Users can change objects properties. Also: When you compare objects with JavaScript’s == operator, it compares by identity: it will produce true only if both objects are precisely the same value. Comparing different objects will return false, even if they have identical properties.

Second Part:
1.
String variables are immutable and therefore if you try to add a new property, it doesn’t stick(change).
For example:

let kim = "Kim";
kim.age = 88;
console.log(kim.age);
// → undefined

It can be useful for a function to accept any number of arguments. For example, Math.max computes the maximum of all the arguments it is given.

Skip

Object serialization is the process of converting an object’s state to a string from which it can later be restored. That means it is converted into a flat description. A popular serialization format is called 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 not allowed in JSON.


#56

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?

Jacques is randomly turning into a weresquirrel, and needs to know what is causing his transformation from human -> squirrel. In order to figure out what triggers his condition, he has to collect lots of data to narrow down what the cause might be so he can avoid it and finally free himself from turning into a man-squirrel. This would present a problem if the only variable types were “string” or “integer” because he’s going to have a lot of data in his log…not just 1 single data point that he can easily represent as a single string or integer.

For example, if Jacques wanted to store multiple values in the form of a string (lets say the values are the number of nuts he sees each day, recorded by day, for a week), his string would be awkwardly represented as “2 3 5 6 11 9 0” . However, this would not work well because every time you would want to access this data, you would have to convert the string back to a number to make it useable again.

2. What variable type can be used in order to solve the problem of storing multiple values?

Arrays can be used to solve the problem of storing multiple values because that’s what they are designed to do! Be a list of values of the SAME TYPE that is easily indexable. Where the first element of the array is stored under the index of “0” NOT “1” as you might think.

an array is written like so:

let listOfNumber = [2, 3, 5, 7, 11];
console.log(listOfNumbers[2]);
//5

3. What are properties in Javascript?

A property is the association between a key (or name) and it’s value, and can be thought of as a key value pairing. It is constructed by joining a properties given name with it’s associated value. All values have an associated property minus the 2 mentioned in question 4–‘null’ + ‘undefined’. In an array, the number in the index between the brackets is the name of the property being searched for within the array it’s applied to:

array[i] = returns element at index ‘i’ (also known as the property named ‘i’).

4. Which values do not have properties?

“Null”
“Undefined”

5. How can we access properties in a value (two ways)?

a) value.x - this accesses a property with the ‘property name’ of “x”. This grabs the property of ‘value’ with name “x”. There is no evaluation, the ‘.x’ is the literal property name of the property being accessed.
b) value[x] - this accesses a property in a slightly different way…by evaluating the expression within the ‘[]’ and then takes the result–converted into a string–as the ‘property name’

6. What are methods?

Properties that contain functions of the values they belong to. A good example of this is below where “‘toUpperCase’ is a method of a string”:

let jake = “jake”;
console.log(jake.toUpperCase);
//JAKE

This type of property is special because instead of just returning a unique part of the value the method was called upon, but that already exists within the value it is applied to, a method applies a function to that value to manipulate the value before returning it. The example above shows this with the value being manipulated into all CAPS before being returned.

7. What are objects?

Objects are arbitrary collections of properties. They can be used to bundle multiple values together behind a single variable that houses everything. One way to create an object is highlighted in the following example that uses curly braces ‘{}’ to house the contents of the object named “day1” which refers to day1 of Jacques log of squirrel transformations. The object shows that he did NOT turn into a squirrel that day despite having engaged in the array of events listed below. The property “squirrel” called on the value “day1” in the form “day1.squirrel” returns “false” because he never turned squirrel on this day:

let day1 = {
squirrel: false,
events: [“work”, “touched tree”, “pizza”, “running”]
};

If you look at the example above, you’ll notice that inside the curly braces ‘{}’ lives a list of properties–in this case only 2–that are separated using the ‘,’ also known as the comma. These properties are broken up into 2 parts that are separated by a colon:

a) the property name - (in the example these were: squirrel, events)
b) the property value - (in the example these were the boolean of ‘false’, and array starting w/ [“work”, …]

The name is always to the left of the colon, and the value is always to the right. Now that objects have been introduced, we have seen all use cases for ‘{}’ in javascript. When set equal to a variable, the braces represent an object. However, when at the start of a statement, they begin a block of statements (think loops+if statements).

delete removes a named property from an object…however its not common practice. Example below:

let anObject = {left: 1, right: 2};
delete anObject.left;
console.log(anObject.left);
// → undefined

In operator tells whether or not an object has a specified property or not. If a property is deleted, then it will return false here, however if a property is set to “undefined” it will still return ‘true’ if the in function searches for it. Shown below in the example that follows from the previous example:

console.log(“left” in anObject);
// → false
console.log(“right” in anObject);
// → true

Object.keys is useful when determining what properties an object has. Given ‘object’, object.keys will return an array of strings consisting of the object’s property names.

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 allow us to store multiple value types in one single variable. Without this data structure, we could not house multiple types of data together all under 1 roof. You could store a boolean, array, and string all in a single object. This is useful if you want to group data of a variety of types together based on the data’s shared connection to the larger idea. In the weresquirrel story, this could be used to store all the data in Jacques log for day ONE (including: turnedSquirrel (boolean), locations visited (array), the days’ outfit (string), etc.). Using an object is the only way Javascript can complete this task.

9. How do you define an object?

An object is a datastructure that can house any other type of datastructure and is a sum of it’s subsidiary properties (a key/value pair) that compose the body of the object. These properties can be any data type you need them to be.

10. What can you say about the mutability of Javascript objects?

Objects in Javascript are very mutable because many functions (such as “delete”) can change the properties that compose the greater object. In this way, objects are different than the original types of values discussed (numbers, strings, and Booleans), which are all **IMMUTABLE*–meaning that it is impossible to change the value of these types after the value has been created. Put more simply, once a string is create–as in the word “cat”, it is impossible for another piece of code to change the first letter of the word–as in “cat” being changed to “rat”. No matter what, the value of that string will remain the same to JavaScript.

Objects work differently because at 2 different times you could have the same object–after changing some of it’s properties–yield 2 different versions of itself…something unheard of with the previously mentioned Immutable data types. A way to visualize this is through the following example that showcases how an object containing the same properties is not the same as the objects being binded to one another…this is due to the mutable nature of Objects. If an object starts out being built from identical properties as another object, and then 1 of them experiences a change in their properties (don’t forget, objects are mutable so this 100% possible), then the 2 are no longer the ~same~ object as one another—in reality they never were to begin with, but this is the rational for why that’s the case. The code example that follows will help illustrate this:

let object1 = {value: 10};
let object2 = object1;
let object3 = {value: 10};

console.log(object1 == object2);
// → true
console.log(object1 == object3);
// → false
object1.value = 15;
console.log(object2.value);
// → 15
console.log(object3.value);
// → 10

One final thing to note about mutability is with regards to bindings. Despite what may be true for the mutability of different value types, bindings are still mutable because you can change the value the binding points at (regardless of whether or not you can change the actual value itself). For example:

const score = {visitors: 0, home: 0};
// This is okay
score.visitors = 1;

// This isn’t allowed
score = {visitors: 1, home: 1};

SECOND PART:

1. Why can’t you add new properties to a string variable?

The ‘string’ data type is immutable and does NOT save the properties that you add to the string. This is because the ‘string’ data type (like ‘number’ and ‘boolean’) is not an object.

2. What are rest parameters?

A ‘rest parameter’ is a parameter for a function that can accept any number (aka an infinite amount of) arguments when passed to the function. A good example of this is the Math.max function that computes the max of ALL arguments given to it (and there is no limit to how many arguments it can accept). This is written by leaving 3 dots before the parameters name in the function construction as shown below:

function max(…numbers) {
let results = -Infinity;
for (let number of numbers) {
if (number > result) {
result = number;
}
}
return result;
}
console.log(max(4, 1, 9, -2));
// -> 9

The values of a REST PARAMETER are bundled into an array with all others associated with that particular argument. If there’s other parameters to meet before the rest parameter, then they will NOT be packaged in the array too, but instead stored as their own separate entity.

4. What is serialisation and what is a use case of serialisation of data?

The process of turning data into a format more suitable for transfer to another computer. This creates a flat description of the data rather than packaging and exporting the entirety of a computers memory to another user. The best known use case for this data manipulation technique is turning object properties (ie. their names + associated values) into JSON format so it is easily readable by other’s machines.

5. What is JSON?

A serialized format used commonly for data transfer on the web in JavaScript (and even in other languages). It stands for JavaScript Object Notation and looks very similar to JavaScript’s way of writing arrays and objects with a few restrictions:

a) property names must be surrounded by double quotes
b) only simple data expressions can be included <- (ie. nothing that requires computation like function calls or bindings)
c) no comments allowed

Example of format as journal entry:

{
“squirrel”: false,
“events”: [“work”, “touched tree”, “pizza”, “running”]
}

6. What are the differences between JSON and the way programmers write objects in plain Javascript?

mentioned above, here they are again:

a) property names must be surrounded by double quotes
b) only simple data expressions can be included <- (ie. nothing that requires computation like function calls or bindings)
c) no comments allowed


#57

Why can’t you add new properties to a string variable?
A string is a primitive type and they are inmutable.

What are rest parameters?
It s the last parameter of a function denoted with 3 dots before the name and is used for functions that can contain any number of parameters.

(Feel free to skip the sub-chapter of Math object and Destructing)
What is serialisation and what is a use case of serialisation of data?
serialization of data is converting all the data in memory to a flat format and saving it into a file.
What is JSON?
java script object notation. a type of serialization format.
What are the differences between JSON and the way programmers write objects in plain Javascript?
All the properties have to be between qoutes , no functions or bindings allowed , neither comments.


#58

What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?

The weresquirrel needed to record data of his daily activities but required a data structure which could store more than just a single string or number. His data structure needed to contain a compilation of strings, with an associated Boolean value and the ability to add additional values to it.

What variable type can be used in order to solve the problem of storing multiple values?

An array, as it stores sequences of values. It is written as a list of values between square brackets, separated by comma’s. Each value is positioned in the array with an index number, the first position starting from zero. You can reach for a contained value by appending at the end of the array name an index (or range) of index numbers between square brackets

var pizzaToppings = [cheese, pepperoni, mushroom];
console.log(pizzaToppings[1]);
// pepperoni

What are properties in JavaScript?

Properties define characteristics of values. As an example, a Blue car has a color property of: Blue.

Which values do not have properties?

The only two values which do not have properties are null & undefined.

How can we access properties in a value (two ways)?

Properties of a value can be accessed by a dot followed with the property name, or with square brackets. The difference is If using a dot, the part after the dot must be a valid variable name as it directly names the property. When using square brackets the expression between the square brackets is evaluated and the result is used to extract the property name.

What are methods?

Methods are functions stored as object properties; in which are actions that can be performed on objects.

What are objects?

Objects are variables too, but they can include many values. Objects have arbitrary collections of properties (name:values pairs) and we can use methods to perform actions on objects.

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 solve for being able to make a single data structure which can organize related data and functionality, along with the ability to set (update) the values wrapped in that object.

How do you define an object?

You define and create a JavaScript object by naming a variable and setting it between curly braces with each property name:value pair separated with commas between them.

var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

What can you say about the mutability of JavaScript objects?

If the characteristic of a datatype is immutable it means that it cannot be changed. In JavaScript numbers, strings & Boolean’s are immutable, therefore it is impossible to change an existing value of those types. However objects in JavaScript are mutable and the contents of a value can be modified by changing its properties.

Why can’t you add new properties to a string variable?

This is because the values of a string are immutable and cannot be changed. However, strings have some built in properties and a number of methods such as slice method, indexOf method & trim method.

What are rest parameters?

The syntax for a rest parameter is three dots (…) prefixing the last parameter in a function. This last parameter is called the rest parameter. Rest parameters represent an unknown number of parameters as an array in a function. (Remember, in JavaScript you can pass in as many parameters into a function as you would like!). You can perform operations on rest parameters such as push, pop etc.

What is serialization and what is a use case of serialization of data?

Serialization is the process of converting an object to a string from which it can later be restored. JavaScript has native functions which serialize and restore JavaScript objects to/from JSON syntax. JSON syntax is a text-only subset of JavaScript syntax, and it cannot represent all JavaScript values. A suitable use case of serialization of data is exchanging it between a browser and a server since it is lightweight.

What is JSON?

JSON stands for JavaScript Object Notation. It is used as a data storage and communication format (standardized) on the web.

What are the differences between JSON and the way programmers write objects in plain JavaScript?

The main differences are that JSON does not allow for function calls, variables or anything that involves actual computation. Comments are not allowed in JSON. A subtle syntax difference is that all property names have to be surrounded by double quotes.


#59

What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?

Problems in which the information comes in groups, like lists. For instances, a problem that involves as variables the information about a customer (age, address, name, etc).

What variable type can be used in order to solve the problem of storing multiple values?
Arrays and objects.

What are properties in Javascript?
Values in JS have properties. They can be accessed with the notation: value.property.

Which values do not have properties?
Null and undefined.

How can we access properties in a value (two ways)?
If x=[1,2,2.5]
Dot notation: x.length=5
Bracket notation: x[“length”]=5

What are methods?
Are processes that you can pass to an array (or string). In other words, are
objects that contain functions that act on an array (or string).

What are objects?
Objects are data sets that consist of a key pair. The pair consists of a property
(identified by its name) and its value. For instance in

day1 = {
squirrel: false,
events: [“work”, “touched tree”, “pizza”, “running”]
};

the object has 2 key pairs.
The property named squirrel has a value “false”.
The property named events has a value that happens to be an array.

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)?

I think problems with many levels of abstraction. A problem can have variables which in turn contains nested information and we need to manipulate information on each level. For instance, in real e
state, you can have
an object named HaouseDescription, with properties
Rooms
Bathrooms
Garden
and in each property, you can have an array that contains size, color, if it requires repairs etc.

How do you define an object?
property: value

What can you say about the mutability of Javascript objects?
You can change the value inside an object. For instance, if you object have a property named CostumerName, you can run a method
on the value of this property to capitalize all the names.

Second part.

Why can’t you add new properties to a string variable?
Because strings are not objects. They are immutable.

What are rest parameters?
Is a method to pass a function an unspecified number of parameters.

What is serialisation and what is a use case of serialisation of data?
Serialization is to convert the data to a flat format so that it can be easily
transmitted over the internet. A use case: storage of information.

What is JSON?
A serialization format.

What are the differences between JSON and the way programmers write objects in plain Javascript?
All property names have to be surrounded by double quotes. No functions are allowed or anything that
requires computation.


#60
  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?
    entries do not consist of just a number or a string—each entry needs to store a list of activities and a Boolean value that indicates whether Jacques turned into a squirrel or not
  2. What variable type can be used in order to solve the problem of storing multiple values?
    Fortunately,JavaScriptprovidesadatatypespecificallyforstoringsequences of values. It is called an array and is written as a list of values between square brackets, separated by commas.
  3. What are properties in Javascript?
    These are expressions that access a property of some value. In the first case, we access the length property of the value in myString. In the second, we access the property named max in the Math object (which is a collection of mathematics-related constants and functions).

  1. Which values do not have properties?
    Almost all JavaScript values have properties. The exceptions are null and undefined

  1. How can we access properties in a value (two ways)?
    ThetwomainwaystoaccesspropertiesinJavaScriptarewithadotandwith square brackets. Both value.x and value[x] access a property on value—but not necessarily the same property
  2. What are methods?
    Both string and array objects contain, in addition to the length property, a number of properties that hold function values

  1. What are objects?
    A set of daily log entries can be represented as an array. But the entries do not consist of just a number or a string—each entry needs to store a list of activities and a Boolean value that indicates whether Jacques turned into a squirrel or not

  1. 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)?
    see point 7 above
  2. How do you define an object?
    One way to create an object is by using braces as an expression.
    let day1 = { squirrel: false, events: [“work”, “touched tree”, “pizza”, “running”] };
  3. What can you say about the mutability of Javascript objects?
    We saw that object values can be modified. The types of values discussed in earlier chapters, such as numbers, strings, and Booleans, are all immutable—it isimpossibletochangevaluesofthosetypes. Youcancombinethemandderive new values from them, but when you take a specific string value, that value will always remain the same

  1. Why can’t you add new properties to a string variable?
    Values of type string, number, and Boolean are not objects, and though the language doesn’t complain if you try to set new properties on them, it doesn’t actually store those properties. As mentioned earlier, such values are immutable and cannot be changed
    let kim = “Kim”;
    kim.age = 88;
    console.log(kim.age);
    // → undefined

  1. What are rest parameters?
    When such a function is called, the rest parameter is bound to an array containing all further arguments
    let words = [“never”, “fully”];
    console.log([“will”, …words, “understand”]);
    // → [“will”, “never”, “fully”, “understand”

  1. What is serialisation and what is a use case of serialisation of data?
    What we can do is serialize the data. That means it is converted into a flat description

  1. What is JSON?
    .A popular serialization format is called JSON (pronounced “Jason”), which stands for JavaScript Object Notation. It is widely used as a data storage and communication format on the Web, even in languages other than JavaScript

  1. 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. Comments are not allowed in JSON.