Excellent answer sir! really well documented! keep it like that please!
Carlos Z.
Excellent answer sir! really well documented! keep it like that please!
Carlos Z.
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?
The problem is the amount of information and the organization of that information effectively. For a program to be able to deal with a group of information (numbers, strings or booleans) efficiently, the program must be able to group values in arrays or objects so that more complex data structures are possible, facilitating the consultation or use of that information efficiently.
2 hat variable type can be used in order to solve the problem of storing multiple values?
Objects / Arrays
3 What are properties in Javascript?
Properties are characteristics associated with a value.
Some properties are inherent to a value, as in the case of a string that has a propertie that represents the character length of the string.
Other properties, in addition to the inherent ones, can be assigned to a value through a key / value association. These properties can be defined within an object.
4 Which values do not have properties?
Null and Undefined
5 How can we access properties in a value (two ways)?
JS has two ways to access the properties of a given value. When we know the name of the property to be used we use:
value.x
where x is the name of the property e. is the character to indicate what to do.
When using an expression, to obtain a string that indicates the name of the property, we use:
value [x]
where where x is the property derived from the string obtained by an expression elaborated by the dev. Property name and [] are the characters to indicate what to do.
6 What are methods?
They are functions defined in an object
7 What are objects?
Objects are data structures used to store a collection of arbitrary properties, through associations of key / value pairs.
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)?
Integer, string and booleans are combinable and derivable, however they are immutable and this makes it impossible to use them in situations where the data needs to be updated or modified. Objects and Arrays both allow modifications to the object value, however Objects are more efficient ways to create data structures to organize a set of information, through properties you can make assumptions between values and “binding keys” while the Array is more suitable for organize an ordered list of values. Objects and arrays have different ways to query and edit the values contained in them.
9 How do you define an object?
First we define a variable. This variable is followed by = {}, where we insert all the desired objects into the curly brackets. The object is defined by a key (word chosen to refer to the corresponding values) and a value or array corresponding to that key. Examples:
// Basic object syntax
var object = {
key: ‘value’
};
// Example ‘person’ object
var person = {
name: ‘Zac’,
age: 33,
likesCoding: true
};
10 What can you say about the mutability of Javascript objects?
Mutability is the ability to change values.
The Primitive Data is on the Stack and the Reference Data is on the Heap.
Primitive type data (numbers, strings, booleans, null, undefined and symbols) cannot have their values changed, only derived or combined into new values.
Reference data can have its values modified. Therefore, objects will have different properties / values at different times. Two objects can have the same properties and not be considered the same by Javascript, because their respective pointers are not indicating the same object, but another object with the same properties. In the opposite case, it is possible to have an object associated with more than one pointer, which Javascript considers to be the same.
Second Part
1 Why can’t you add new properties to a string variable?
By definition, strings, numbers and booleans are not objects and are immutable, so JS does not allow new properties to be stored for strings, numbers and Booleans, but they do have some properties intrinsic to them. The string for example had an intrinsic property called lenght.
2 What are rest parameters?
is a new form of syntax adopted by Javascript in 2015 to simplify the code and give greater versatility to define function parameters. Through the rest parameters we can assign numerous parameters to a function through 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?
It is converting data into a flat description. JS stores objects and arrays in the system memory in bit format, to save this information it is stored for later use or to be communicated over the network, it is necessary to convert this data tangle. Serialization is used so that the data contained in the heap can be “saved” in a flat description and retrieved in the future, this allows to preserve the integrity of the data and to compress only the essential amount of essential information in the computer’s memory.
5 What is JSON?
JSON stands for Javascript Object Notation and is a popular format for serialization, used for storage and data communication.
6 What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON requires that key / value pairs of objects have double quotes, so single quotes are replaced by double quotes for key and value.
There can be nothing that involves computation, such as bindings, called functions and methods.
Comments cannot exist.
Although strings and integers can hold data, they are limited. The person in the chapter would need to hold multiple values inside a single database.
Arrays a possible way to store multiple values.
Javascript values have properties unless they are NaN or undefined. For example, myString.length (to get the length of a string) and Math.max (the maximum function) are expressions that access a property of some value.
NaN or undefined
With a dot or square brackets. Both value.x and value[x] access a property on value but not necessarily the same property.
Properties that contain functions are generally called methods of the value
they belong to. For example, the push method adds values to the end of an array, and the pop method does the opposite, removing the last value in the array and returning it.
let sequence = [1, 2, 3];
sequence.push(4);
sequence.push(5);
console.log(sequence);
// → [1, 2, 3, 4, 5]
let day1 = {
squirrel: false,
events: [“work”, “touched tree”, “pizza”, “running”]
};
console.log(day1.squirrel);
// → false
They can contain many different kinds of data unlike strings, arrays, booleans etc**
It’s a variable which has values included in braces.
Mutability is about changing values. This is possible in objects but not elsewhere such as strings which retain the set values.
Second part:
Strings are cannot be altered (they are immutable).
Rest parameters are bound to an array which includes arguments. To add a rest parameter, we need to use three dots before the last parameter. It’ll then include all the values.
let numbers = [15, 8, 20];
console.log(max(…numbers));
// → 20
Done
Serialisation converts data stored in memory into a flat description of what that data is. It can be useful when we want to transfer our work to another computer.
JavaScript Object Notation is a format widely used for data storage and communication.
Only simple expressions can be used in JSON. There are no functions, bindings, comments, or computations.
Part 1
Variable types like strings or integers are immutable, meaning you cant change their values as opposed to Object type which you can change their properties and have different content at different times.
To store multiple values in JavaScript we can use variable types like arrays and objects.
All JavaScript values have properties with the exception of NULL and UNDEFINED which throw out an error if we try to call the property value of these two.
NULL and UNDEFINED do not have properties.
To access the property of any JavaScript values, we either use the dot or the square bracket notations.
Methods are basically value functions of properties OR properties that contain functions are called methods.
Objects are arbitrary collections of properties. To create an object we use braces and inside the braces a whole list of properties separated by commas. Each property has a name followed by a colon and a value. Braces have two meanings in JavaScript. Firstly, braces are used to start a block of statements. Secondly its used to create an object.
Objects are not restricted by the immutability constrain. In other words, objects’ values can change or modify. You can change their properties causing a single object value to have different content at different times.
To create an object we use braces and inside the braces a whole list of properties separated by commas. Each property has a name followed by a colon and a value.
The mutability of JavaScript’s objects allows flexibility in coding without the need to redefine each and every object to be created for use.
PART 2
String variables are immutable. You cannot changed the value prepositions of string once its created. For instance the string " CAT " cant be changed to " RAT ". However you can set new properties on them but it will not be stored. Every string value has a number of inbuilt methods.
Functions have parameter fields which are called by passing arguments from other functions. Rest parameters are parameters that take in an array of arguments with the" three dots notation" without having to fully list the array elements.
Because objects and arrays only “grab” the values in JavaScript, both arrays and objects are stored in the computer"s memory as sequence of bits as addresses rather than their contents in memory… Thus if we want to send this memory file across devices , we can " serialize " the data into flat file format rather than sending a whole nested layers of memory files.
JSON or JavaScript Object Notation is a popular serialization format of storing data and for communicating across the web.
JSON are almost similar to JavaScript’s way of writing arrays and objects.except that the differences are that in JSON all property names must be surrounded in double quotes, no function calls, no bindings or anything that involves actual computations.
Part 1:
Part 2:
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?
Anyone else find this story odd? Anyhow - repeatedly writing and tracking so many variables becomes unruly - leaving an array as a much better solution
What variable type can be used in order to solve the problem of storing multiple values?
array
What are properties in Javascript?
values as named strings associated with objects
Which values do not have properties?
null and undefined
How can we access properties in a value (two ways)?
as strings inside brackets or . dot notation
What are methods?
An integrated function that is a property
What are objects?
values that are collections 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)?
Various properties can be added removed or created
How do you define an object?
By the use of curly braces
What can you say about the mutability of Javascript objects?
The values can be modified.
Why can’t you add new properties to a string variable?
Strings are immutable - and does not have the ability to add new properties
What are rest parameters?
Allow to represent arguments as an array
What is serialisation and what is a use case of serialisation of data?
Changing the data to a flat description -
What is JSON?
JavaScript Object Notation
What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON has all property names captured in double quotes and no comments or functions allowed.
Part 1:
1 - The Weresquirrel problem demonstrates the limitation of basic variables when trying to solve complex problems involving many data points. The importance of arrays and objects is apparent here when we need to work with large data sets.
2 - To store multiple values we can use an Array which can hold multiple items which are either integers or strings. We can also use Objects.
3 - Javascript assigns properties to all values ( things like .length). Properties can also be defined in Objects .
4 - Null and undefined do not have properties.
5 - array.length or array[“length”] are two ways to return the same value .
6 - A method is a property which contains a function i.e. array.push(5) push has an argument so it is a method.
7 - Objects are collections of data which are bound to a variable name. Each entry in an object has a property (a name) and a value. The value can also be an array.
8 - Objects lend themselves to analysis of large sets of data.
9 -
let newObject = {
trees: [“oak”, “fir”, “maple”],
cars: [“skoda”, “bmw”, “mercedes”],
bears: [“polar”, “black”, “koala”]
}
10 - Javascript objects can have individual values changed, even if they are declared as const .
Part 2:
Strings and Integers are single entities. When a data set is needed arrays must be used.
Arrays can be used to solve the problem of storing multiple values.
Properties and JavaScript are the characteristics of a value. Eg. length of a string.
Null and Undefined do not have properties.
We can access properties in two ways. 1) With a dot (Math.max) and 2) With square brackets Value[1].
Properties that contain functions are generally called methods of the value they belong to.
Values of the type object are arbitrary collections of properties.
Objects are able to hold different data types.
let objectA = {a:1 , b:2};
You can change their properties causing a single object value to have different content at different times - therefore mutable.
Properties can not be added to a string variable because it is immutable.
The use of any number of arguments in a function denoted by three dots.
Data is converted into a flat description.
JavaScript Object Notation - widely used as a data storage and communication format on the web.
Simple expressions are used JSON. There are no functions, bindings, comments or computations.
Part 1
PART TWO
Strings are immutable.
Using rest parameters, we can pass in any amount of arguments to a function.
Rest parameters are defined by three dots in front of the last function parameter: ‘…’
Serialisation is the process of changing data into a format that can be easily stored in memory or can be easily sent across the network.
JSON stands for JavaScript Object Notation. JSON is text, written using JavaScript syntax for storing and exchanging data.
In JSON property names, and string values of an object are both in between double quotes. JSON can’t include function calls and other computation.
Good answers!
Here’s a few additional points to consider …
… yes, and a key point here is he needs to store multiple sets of related data, and in such a way that it can be effectively manipulated and analysed.
Yes, and they also allow related data of different types to be grouped and stored together under one roof in a single value.
You’re right about the objects, but don’t get confused between variables and values. Objects are a type of value (not variable). Objects, like any other type of value (objects, strings, numbers, booleans etc.) can be stored in variables, and these variables can always have their value reassigned (changed) to a different one.
Yes…and in JSON:
(i) all property names must be written within double quotes;
(ii) double quotes must be used for all string values (i.e. no option to use single quotes);
Good answers!
Have you already done (and posted) the Part 1 questions 1-10 ?
Yes, property names must be written in double quotes, but not all values, only strings. What may be confusing, is that numbers can be stored as either strings or number types. For example, we may want to store a reference number as a string (so in JSON it would have double quotes). But, otherwise, our number type won’t have any double quotes (e.g. storing a person’s age).
Hi Jon,
Yes, i have posted the first part a few days ago, I have started writing the answers, and then I ran out of time, so I figured I’ll post the first part and finish the second part later.
https://forumtest.ivanontech.com/t/data-structures-arrays-and-objects-reading-assignment/3116/315?u=zoltan
You are totally right! I just had a look through my notes, and I realised that the value for ‘age’ property name is without quotes.
Thank you for pointing my mistake out, I’ll go back and edit my answer.
Zoltan
Great!..I see now that @thecil has already reviewed your Part 1 answers
Keep up the good work!
Yes, he did.
Thank you
thanks for pointing out these subtleties
Part 2
What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
With multiple values and variables, there is no singular result. There need to be easy access to systematized data in order to process information and compare the results in order to find out what conditions triggers the transformation.
What variable type can be used in order to solve the problem of storing multiple values?
For larger structures is can be a variation of Objects. One of the most commonly used Objects are Arrays. Which are Objects handling sequence
What are properties in JavaScript?
The definition of characteristics a value holds
Which values do not have properties?
Null and Undefined
How can we access properties in a value (two ways)?
With a dot or square brackets
array.length
array[x]
What are methods?
Properties that hold function values, such as .push
What are objects?
Objects are data structures holding the values of an arbitrary 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)?
Aside from being able to contain the values mentioned, objects will process the attached values the same way even if the inherit property of said value is changed.
How do you define an object?
Objects are defined by a braced value
What can you say about the mutability of Javascript objects?
It provides the code with flexibility
Why can’t you add new properties to a string variable?
String variables are immutable
What are rest parameters?
A reference to code outside of the parameter such as …words
if you create an array such as:
let words = [hej, svejs, fejs] ;
You can later call on that array with …words
What is serialisation and what is a use case of serialisation of data?
Conversion of data into a stored flat description to send the information as a file or across a network
What is JSON?
A popular storage and communication format
What are the differences between JSON and the way programmers write objects in plain Javascript?
It’s more restrictive and less flexible. JSON only allow simple values expression like strings, numbers, arrays and booleans
All property names need to have double quotes, comments aren’t allowed, nor bindings, function calls or any actual computation
Second part
Why can’t you add new properties to a string variable?
What are rest 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?
What is JSON?
It doesn’t actually store those properties. As mentioned earlier, such values are immutable and therefore it cannot be changed.
Rest parameters are bound to an array containing all further arguments.
–
Serialization is to serialize the data. That means it is converted into a flat description.
JSON is a popular serialization format, 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.
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?
Data structures.
What variable type can be used in order to solve the problem of storing multiple values?
An array can be used for that purpose.
What are properties in Javascript?
Expressions that can be applied to data structures to get certain values or information.
Which values do not have properties?
null
and undefined
How can we access properties in a value (two ways)?
The dot .
or square brackets []
.
What are methods?
Special functions associated with a particular data type / value.
What are objects?
A container of multiple 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)?
Objects can contain multiple (different) value types. They also help us to encapsulate functionality and give us a higher abstraction level.
How do you define an object?
A container holding multiple values and implementing some functionality with which we can interact using it’s properties and methods.
What can you say about the mutability of Javascript objects?
The mutability of JavaScript objects refers to the fact that their properties can be changed at anytime.
Why can’t you add new properties to a string variable?
Because string variables are not mutable.
What are rest parameters?
A way to pass variable length parameters to a function (putting 3 dots ...
before the last parameter).
What is serialisation and what is a use case of serialisation of data?
The process of converting the values that our program is holding in memory to a format that can be stored o sent via the network.
What is JSON?
JSON stands for JavaScript Object Notation. And it is a data format that can be used to store or send information.
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, and only simple data expressions are allowed—no function calls, bindings, or anything that involves actual computation.