- 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.
- What variable type can be used in order to solve the problem of storing multiple values? An array.
- What are properties in Javascript? Properties are values of objects (ie: length.string is the length value of the string object.)
- Which values do not have properties? Almost all JavaScript values have properties. The exceptions are null and undefined
- 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â - 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. - 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).
- How do you define an object? You can use braces as an expression.
- 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:
- Why canât you add new properties to a string variable? Strings are immutable.
- What are rest parameters? Rest parameters allow a function to take in an indefinite number of arguments and condense them into an array.
- (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? 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).
- 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.
- 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.