Data Structures (Arrays and Objects) - Reading Assignment

Excellent answer sir! really well documented! keep it like that please! :muscle:

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.

1 Like
  1. 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.

  2. Arrays a possible way to store multiple values.

  3. 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.

  4. NaN or undefined

  5. With a dot or square brackets. Both value.x and value[x] access a property on value but not necessarily the same property.

  6. 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]

  1. Arbitrary collections of properties. The person in the story may change into a squirrel one day and the other stay the same, this can be taken into consideration within objects.

let day1 = {
squirrel: false,
events: [“work”, “touched tree”, “pizza”, “running”]
};
console.log(day1.squirrel);
// → false

  1. They can contain many different kinds of data unlike strings, arrays, booleans etc**

  2. It’s a variable which has values included in braces.

  3. Mutability is about changing values. This is possible in objects but not elsewhere such as strings which retain the set values.

Second part:

  1. Strings are cannot be altered (they are immutable).

  2. 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

  1. Done

  2. 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.

  3. JavaScript Object Notation is a format widely used for data storage and communication.

  4. Only simple expressions can be used in JSON. There are no functions, bindings, comments, or computations.

1 Like

Part 1

  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.

  2. To store multiple values in JavaScript we can use variable types like arrays and objects.

  3. 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.

  4. NULL and UNDEFINED do not have properties.

  5. To access the property of any JavaScript values, we either use the dot or the square bracket notations.

  6. Methods are basically value functions of properties OR properties that contain functions are called methods.

  7. 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.

  8. 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.

  9. 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.

  10. 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

  1. 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.

  2. 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.

  3. 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.

  4. JSON or JavaScript Object Notation is a popular serialization format of storing data and for communicating across the web.

  5. 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.

2 Likes

Part 1:

  1. Storing large sets of data.
  2. An array can store multiple values.
  3. Properties are the content or characteristics or a given value.
  4. Null and Undefined have no properties.
  5. Two ways of accessing properties are by using a DOT or [ ].
  6. A property that contains a Function is usually called a method.
  7. Objects are an arbitrary collection of properties.
  8. You can change the properties of an object.
  9. You can define an Object with Braces {}
  10. Objects are mutable, Strings, Boleans and numbers are immutable and cannot be changed.

Part 2:

  1. A string variable is Immutable.
  2. Rest parameters allow us to represent an indefinite number of arguments as an array.
  3. Serialisation means the conversion of data into a flat description.
  4. JSON is a format of serialisation. (JavaScript Object Notation)
  5. Differences between JSON and plain Javascript are; JSON cannot contain any comments, function calls, bindings or computations, only simple data expressions are allowed.
1 Like
  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?
    Anyone else find this story odd? Anyhow - repeatedly writing and tracking so many variables becomes unruly - leaving an array as a much better solution

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

  3. What are properties in Javascript?
    values as named strings associated with objects

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

  5. How can we access properties in a value (two ways)?
    as strings inside brackets or . dot notation

  6. What are methods?
    An integrated function that is a property

  7. What are objects?
    values that are 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)?
    Various properties can be added removed or created

  9. How do you define an object?
    By the use of curly braces

  10. What can you say about the mutability of Javascript objects?
    The values can be modified.

  11. Why can’t you add new properties to a string variable?
    Strings are immutable - and does not have the ability to add new properties

  12. What are rest parameters?
    Allow to represent arguments as an array

  13. What is serialisation and what is a use case of serialisation of data?
    Changing the data to a flat description -

  14. What is JSON?
    JavaScript Object Notation

  15. 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.

1 Like

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:

  1. Strings are immutable.
  2. Rest parameters allow us to use an array as an argument in a function.
  3. OK
  4. Serialisation is a way of taking a set of data (for example the contents of an array or object) and separating it out into a format which can reconstructed later. This is useful for taking large amounts of data out of one program/environment and moving it to another.
  5. JSON is Javascript’s way of serialising data.
  6. JSON has no bindings or operations
1 Like
  1. Strings and Integers are single entities. When a data set is needed arrays must be used.

  2. Arrays can be used to solve the problem of storing multiple values.

  3. Properties and JavaScript are the characteristics of a value. Eg. length of a string.

  4. Null and Undefined do not have properties.

  5. We can access properties in two ways. 1) With a dot (Math.max) and 2) With square brackets Value[1].

  6. Properties that contain functions are generally called methods of the value they belong to.

  7. Values of the type object are arbitrary collections of properties.

  8. Objects are able to hold different data types.

  9. let objectA = {a:1 , b:2};

  10. You can change their properties causing a single object value to have different content at different times - therefore mutable.

  11. Properties can not be added to a string variable because it is immutable.

  12. The use of any number of arguments in a function denoted by three dots.

  13. Data is converted into a flat description.

  14. JavaScript Object Notation - widely used as a data storage and communication format on the web.

  15. Simple expressions are used JSON. There are no functions, bindings, comments or computations.

1 Like

Part 1

  1. Integers and strings can only hold value of 1 type. Jaques need multiple types of values to be stored.
  2. Here come Arrays - a type of variable that allows storing mutiple values.
  3. Nearly all JS values have properties - these are characteristics of the values.
  4. Only Null and Undefined don’t have properties
  5. Propreties of a vaue can be accessed in two ways - using a dot and suqare brackets.
  6. Methods are propertis that contain functions.
  7. Objects are collections of properties.
  8. Objects allow the vaues to be modified.
  9. Objects are created by using braces. Inside the braces properties are listed using commas.
  10. Unlike other type of variables, Objects can be modified and have different values at different moments in time.
    Part 2
  11. Strings are immutable and don’t hold newly added properties.
  12. Rest parameters represent any number of arguments as an array.
  13. Serialization means data converted in flat description in order to be ent to another computer.
  14. One of the methods of serilization is called JSON. Its a very popular way of data storage.
  15. JSON looks similar to JavaScript’s way of writing arrays and objects.
  16. Only simple expressions are allowed in JSON. there are no function calls, bindings, or anything that involves actual computation and Comments are not allowed in JSON.
1 Like

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.

1 Like

Good answers! :slightly_smiling_face:

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

1 Like

Good answers! :smiley:

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

2 Likes

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 :slightly_smiling_face:

1 Like

Great!..I see now that @thecil has already reviewed your Part 1 answers :+1:
Keep up the good work! :muscle:

1 Like

Yes, he did. :slightly_smiling_face:

Thank you

2 Likes

thanks for pointing out these subtleties :pray:

1 Like
  1. In order to solve the mystery of the weresquirrel, data structures will be required to handle bundles of values.
  2. Objects are used to store multiple values.
  3. Properties are characteristics of a value, which itself is represented as a value.
  4. Null and undefined have no properties.
  5. Properties can be accessed by using “.” to refer to its string name, or using “[ ]” to refer to its variable name.
  6. Methods are properties that hold function values.
  7. Objects are bundled collections of properties.
  8. Objects can be used to organize groupings of values where as integers, strings and booleans can only bind to a single value. Functions likewise return a single value. Arrays are a specific type of object which is ordered sequentially and therefore lacks the open-ended flexibility of non-array objects. Furthermore, the property values of objects are mutable, giving it more flexibility.
  9. An object is an arbitrary group of properties.
  10. The mutability of objects allows changes to the values of its properties. Therefore, we can make detailed changes to the object without fundamentally altering its structure.

Part 2

  1. String variables are immutable and new properties will not be stored.
  2. Rest parameters refer to a function’s parameters when they take any number of arguments or to an array which contains any number of values.
  3. Serialisation is the conversion of Javascript data from binary bits of memory storage into a flat description which allows for data storage and communication to occur, between computers for example.
  4. Javascript Object Notation is a serialization format, widely used for JS as well as other languages.
  5. In JSON, all property names must use double quotes. Also, no variable names can be used for properties since they require bindings and no methods can be used since they require function calls.
1 Like

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

1 Like
  1. If you want to represent integers and data it’s an akward way to store these data and to extract the digits and convert them back to access them. Time consuming.
  2. By using array these are square brackets where you can write a list of values between square brackets, separated by commas.
  3. Properties are the values associated with a JavaScript object. A JavaScript object is a collection of unordered properties. Properties can usually be changed, added, and deleted, but some are read only.
  4. The exceptions are null and undefined
  5. With the . and with this example value [x] to extract
  6. Properties that contains functions are generally called methods of the value they belong to.
  7. A JavaScript object is a collection of unordered properties.
  8. With objects you can easily control the grouped properties.
  9. One way to create an object is by using braces as an expression example btc: [‘Go Long’, ‘Go Short’, ‘Hodl’]
  10. The types of values discussed in earlier chapters, such as numbers, strings, and Booleans, are all immutable – it is impossible to change values of those types. The text inside cannot be changed.

Second part

  1. Why can’t you add new properties to a string variable?

  2. What are rest parameters?

  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?

  5. What is JSON?

  6. It doesn’t actually store those properties. As mentioned earlier, such values are immutable and therefore it cannot be changed.

  7. Rest parameters are bound to an array containing all further arguments.

  8. Serialization is to serialize the data. That means it is converted into a flat description.

  9. 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.

1 Like
  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?
    Data structures.

  2. What variable type can be used in order to solve the problem of storing multiple values?
    An array can be used for that purpose.

  3. What are properties in Javascript?
    Expressions that can be applied to data structures to get certain values or information.

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

  5. How can we access properties in a value (two ways)?
    The dot . or square brackets [].

  6. What are methods?
    Special functions associated with a particular data type / value.

  7. What are objects?
    A container of multiple values.

  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)?
    Objects can contain multiple (different) value types. They also help us to encapsulate functionality and give us a higher abstraction level.

  9. 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.

  10. 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.

  11. Why can’t you add new properties to a string variable?
    Because string variables are not mutable.

  12. What are rest parameters?
    A way to pass variable length parameters to a function (putting 3 dots ... before the last parameter).

  13. 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.

  14. What is JSON?
    JSON stands for JavaScript Object Notation. And it is a data format that can be used to store or send information.

  15. 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.

1 Like