Data Structures (Arrays and Objects) - Reading Assignment


#163
  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? When there is a need to access a sequence of values, then Strings and integers will not be effective. There would need to be a conversion step for the string for retrieving the value.
  2. What variable type can be used in order to solve the problem of storing multiple values? An array.
  3. What are properties in Javascript? Properties are values of objects (ie: length.string is the length value of the string object.)
  4. Which values do not have properties? Almost all JavaScript values have properties. The exceptions are 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. Both value.x and value[x] access a property on value—but not necessarily the same property.
    6 What are methods? Properties that contain functions are generally called methods of the value
    they belong to, as in “toUpperCase is a method of a string”
  6. What are objects? Values of the type object are arbitrary collections of properties. One way to
    create an object is by using braces as an expression.
  7. 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 created ‘on the heap’, a larger memory space in the computer, so they can be bigger. Primitives are created and managed on the stack (a smaller, limited, faster memory space), that is why they must be relatively smaller (booleans, integers and strings are more manageable in size). When an object is created, it gets a reference as well, which is created on the stack, that points to the actual object on the heap. That reference for the larger object on the heap, is what is passed around when referring to that object elsewhere in the code. This is a faster way to manage the larger objects, because the primitives are copied each time they are created (if you create var name = ‘tim’ and then make secondname = name and then rename name (name = ‘Chris’), after the renaming of name, if you console.log(secondname), you will get ‘tim’. Why? Because the statement name = ‘Chris’ created a new primitive on the stack, and secondname is still pointing to the first one, ‘tim’. This can be problematic, of course: Keeping track of what variables are printed to what primitives might make a mess, with regard to keeping track of them all. On the other hand, objects are simply passed around as references, so, in the same scenario, if you created obj1 {} and then made obj2 = obj1, now obj2 simply has a reference to the data for obj1 on the stack (the data for obj1 is on the heap). If you now change data in obj2 and console.log it, it will reflect the changed data immediately… because both obj1 and obj2 are simply using references, stored on the stack, which are pointing to the same data on the heap. Because objects may be very large, passing around references is obviously much more efficient (faster).
  8. How do you define an object? You can use braces as an expression.
  9. What can you say about the mutability of Javascript objects? strings, integers, numbers and other ‘primitives’ values are not changeable. That means that they are ‘immutable.’ Objects are mutable (they can be changed).

SECOND PART:

  1. Why can’t you add new properties to a string variable? Strings are immutable.
  2. What are rest parameters? Rest parameters allow a function to take in an indefinite number of arguments and condense them into an array.
  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? Serialisation is the method by which the data/program that you are trying to send over the network from your computer to another is ‘flattened’ (versus sending your computer’s memory over the network and all of the references that you have in the current state that your computer has regarding the program … a rather strange way to transmit information).
  5. What is JSON? JSON is the ‘flat version’ of the data on your computer that you are trying to send over the internet to another computer. Since the current state of the program on your computer (before the flattening) is a tangle of addresses in memory, data within each address, and the references that you have to each address, there needs to be a standardized way to complete the process of ‘flattening’ such that any computer that receives it will recognize the format and be able to translate it into a working program on the destination computer. This is what JSON accomplishes, it stands for JavaScript Object Notation.
  6. 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.

#164
  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 needs to store multiple values in a single variable.

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

  3. What are properties in Javascript? They are are expressions that access a property of some value of a variable.

  4. Which values do not have properties? null and undefined

  5. How can we access properties in a value (two ways)? value.x returns the property of value named “x”. value[x] tries to evaluate the expression x and uses the result, converted to a string, as the property name.

  6. What are methods? Methods are properties that contain functions. They are are generally called methods of the value they belong to, as in “toUpperCase is a method of a string".

  7. What are objects? Objects are arbitrary collections 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)? The objects are type of variables extremely flexible to rappresent the entity in a the real world because the structure of an object, its properties and methods, can be freely defined so we can coding using variable with an higher level of abstraction than other values types.

  9. How do you define an object? On object can be defined using braces as an expression:

let client = {
         name: "Mario",
         surname: "Rossi", 
         orders: [ ord909, ord1041, ord357] 
};
  1. What can you say about the mutability of Javascript objects? It’s possible to change an object’s property, causing a single object value to have different content at different times.

SECOND PART

  1. Why can’t you add new properties to a string variable? A string variable is not objects and thei properties are immutable.

  2. What are rest parameters? Rest parameters are bound to an array containing all additional arguments given to a function.

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

  4. What is serialisation and what is a use case of serialisation of data? If you want to save data in a file for later or send it to another computer over
    the network, you have to somehow convert the tangles of memory addresses, related to an object, to a description that can be stored or sent. A solution is serialize the data, that means it is converted into a flat description.

  5. What is JSON? JSON (JavaScript Object Notation) is a popular serialization format that is widely used as a data storage and communication format on the Web, even in languages other than JavaScript.

  6. What are the differences between JSON and the way programmers write objects in plain Javascript? In a JSON file comments are not allowed and 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.


#165
  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?

Variable that can store multiple values.

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

  2. What are properties in Javascript?
    Properties are values inside an object.

  3. Which values do not have properties?
    Nul and undefined

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

  5. What are methods?
    Properties that contain functions are generally called methods of the value they belong to. For example in toUpperCase () is a method of a string.

  6. What are objects?

A JavaScript object is a collection of unordered properties

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

They solve the need to store different data types

  1. How do you define an object?

Object can be defined as binding and its value in braces e.g. let person = {name: “Roland”, age: 49};

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

Objects are mutable as their values can be altered. But primitives are not.

SECOND PART:

  1. Why can’t you add new properties to a string variable?
    They are not treated as Objects.

  2. What are rest parameters?
    rest parameters allow us to call any number of arguments from input data, they allow us to not specify an exact amount of data to be called for.

  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?
    Serialization is the conversion of an object to a string of characters or bytes, the use case is to transmit the object across the network or store it or replicate it to another similar is slightly different object.

  5. What is JSON?
    JSON is JavaScript Object Notation, It is a form of serialization and allows for faster communication among different programs

  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, comments or anything that involves actual computation are not allowed.