- 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!
var text = “123abc”;
The output will be 6 in the console.
Which values do not have properties?
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).
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.
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)
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?
All property names have be surrounded with double quotes and you can only use simple expressions, no calls or bindings, not even comments.