Part one
- 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 begin with, string and integer variable types can only contain one value of data. For example when it comes to a string, you can only add a value ones to that specific variable and that’s it. Same goes for integer type of variables or char. What if you need a variable where you can put multiple data values, or keep adding values as the program goes on?
-
What variable type can be used in order to solve the problem of storing multiple values?
An Array variable. That’s the whole point with arrays, you can store multiple values in an array variable and add even more if you would need it. Its just like the name of the variable suggests, an array of values.
You can even have two- or three-dimensional arrays if needed! -
What are properties in Javascript?
Variables and values have properties in Javascript. A property would be, for example, to get the length of a string. To get the length of the string, you invoke it by its expression. so, you express the property that you would like to invoke.
Example below:
var text = “123abc”;
console.log(text.length);
The output will be 6 in the console. -
Which values do not have properties?
All values in Javascript have properties except for ‘undefined’ and ‘null’. -
How can we access properties in a value (two ways)?
We can do that with either dot (’.’) or square brackets. They don’t work in the same way and perform different tasks but depending on how you write the code and how the JS-machine interprets the ‘x’ value, you could invoke the same property with both ways, all though one way is always more efficent than the other depending on the property you want to access. -
What are methods?
Methods are properties for a value that contains a function. Methods only work for specific function values, for example you could use the .toUpperCase method in a string text to return the text with all the letters capitalized. But you wouldn’t be able to use this method on an integer variable since there is nothing to capitalize. -
What are objects?
Objects are values of arbitrary collections of values. See of it more like a grouping of data. -
What problem do objects solve that cannot be solved with other value types we’ve learned so far?
With objects, we can store many different data types. The value types that we’ve learned so far can only store one type of data. Even arrays, once you’ve decided if your array variable is going to hold integer values or string value, you have to stick to it. You can’t declare an array with integer values and then add string values to a certain element in that array. -
How do you define an object?
You define in just like an other variable, but you add its values inside curly brackets(braces). -
What can you say about the mutability of Javascript objects?
The mutability of objects is just like it sounds, mutation of values in objects, meaning they change. Not that they do, but they can if you so will. Another way of putting it would be references. Two objects referr to one another. When one value changes, then so does the value in the other object aswell. As long as they are referred, they will have the same values, even after changing just one of the objects.
Second part
-
Why can’t you add new properties to a string variable?
Because it is not an object, but a primitive datatype. They are immutable. -
What are rest parameters?
A rest parameter is bound on the array for further arguments. It contains all aditional arguments given to a function. -
(Feel free to skip the sub-chapter of Math object and Destructing)
Skipped! -
What is serialisation and what is a use case of serialisation of data?
Serialisation is when you convert the data that is stored in the memory into a flat description. This is useful for when we save the data to a file or if we want to transfer that data from one computer to another. -
What is JSON?
JSON stands for Javascript Object Notation and it is a serialisation format that is widely used for storing data. -
What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON is familiar with Javascript’s way of writing but it has a few restrictions.
All property names have be surrounded with double quotes and you can only use simple expressions, no calls or bindings, not even comments.