Data Structures (Arrays and Objects) - Reading Assignment

  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 ability to compile data of various types (used strings, new strings, boolean expressions) and analyze this data.
  1. What variable type can be used in order to solve the problem of storing multiple values?
  • An array allows you to store a sequence of values.
  1. What are properties in Javascript?
  • All JS values except below have properties. Properties describe some feature of the data value being examined, such as length etc.
  1. Which values do not have properties?
  • Null and Undefined
  1. How can we access properties in a value (two ways)?
  • value.x and value[x]
  1. What are methods?
  • Methods are JS properties with built-in functions.
  1. What are objects?
  • Objects are arbitrary collections of properties.
  1. 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)?
  • An object can hold different types of data within itself.
  1. How do you define an object?
  • One way:
let sampleObject = {
 object1:false,
 objectArray2:["word", "more text", "still more"]
};
  1. What can you say about the mutability of Javascript objects?
  • You can change the properties of objects, giving an object value different content at different times.

SECOND PART:

  1. Why can’t you add new properties to a string variable?
  • Because it’s immutable.
  1. What are rest parameters?
  • It’s bound to an array containing all further arguments.
  1. (Feel free to skip the sub-chapter of Math object and Destructing)
  2. What is serialisation and what is a use case of serialisation of data?
  • Converting data into a flat description, for instance when you need a list or database accessible to multiple programming languages.
  1. What is JSON?
  • JavaScropt Object Notation is a serialization format.
  1. What are the differences between JSON and the way programmers write objects in plain Javascript?
  • Some differences: All property names have to be surrounded by quotes, and comments are not allowed.
1 Like

Hi @Antonastrm,

Mostly good answers :ok_hand:

Just a couple of observations…

… and the question also asks for a use case of serialisation of data — can you name or describe one?

…you wrap keys (property names) in double quotes, but you only wrap string values in double quotes: other values, such as numbers, Booleans and null, are written without quotes.

1 Like

Hi @aryakrishna,

Mostly good answers :ok_hand:

Just a couple of observations…

… not really… properties are name (key) / value pairs which store information about a value e.g. a string has a length property which stores as its value the number of characters in the string.

The typeof operator returns the value type of the value that follows it e.g.

console.log(typeof []);         // => object (arrays are a type of object)
console.log(typeof {});         // => object 
console.log(typeof 5);          // => number
console.log(typeof false);      // => boolean
console.log(typeof "object");   // => string

The question asks how we define an object, and this refers to how we create one…

let objectName = {
   propertyName1: value,      
   "Property Name 2": value,
   propertyName3: value
   // etc.
};
1 Like

thanks jon!! really appreciate this…having hard time to understand :slight_smile:

1 Like

You’re welcome!
Don’t forget that in these discussion threads you can ask questions about anything you don’t understand in the assignments, as well as post your answers.
We’re here to help :slightly_smiling_face:

2 Likes
  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?
  • Our friend needs to store more than one data type. A data structure that stores more than one data type is needed.
  1. What variable type can be used in order to solve the problem of storing multiple values?
  • Arrays
  1. What are properties in Javascript?
  • Properties are things that allow us to do something with the data inside the arrays/object.
  1. Which values do not have properties?
  • Null & undefined
  1. How can we access properties in a value (two ways)?
  • value.property & value[property]
  1. What are methods?
  • Methods are properties that contain functions for example changing all the letters in a string to uppercase letter.
  1. What are objects?
  • Objects are data structures that contain different data types as attributes.
  1. 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 store more than one data type such as integers, booleans, strings, arrays.
  1. How do you define an object?
  • Example, var house = {material: “brick”, color: “white”, rooms: 3}
  1. What can you say about the mutability of Javascript objects?
  • Can someone please explain this to me, I don’t really understand mutability?
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? To understand which event may cause the health problem he should put on the code all the data about his daily reactions to elaborate them.
  2. What variable type can be used in order to solve the problem of storing multiple values? Array can store multiple values
  3. What are properties in Javascript? Properties define characteristics of values
  4. Which values do not have properties? Null and undefinied
  5. How can we access properties in a value (two ways)? With a dot and with square brackets
  6. What are methods? Properties that contain functions
  7. What are objects? Arbitrary 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)? Objects may contain different kinds of data and can be modified, unlike the other value we have learned so far.
  9. How do you define an object? As all definitions can be given by brackets
  10. What can you say about the mutability of Javascript objects? Mutability means that the objects may be modified

Think about the following questions:

  1. Why can’t you add new properties to a string variable? Only objects can be changed
  2. What are rest parameters? When a function is called, the rest parameter is bound to an array containing all further arguments
  3. What is serialisation and what is a use case of serialisation of data? Converting data into a description
  4. What is JSON? It’s a popular serialization format
  5. What are the differences between JSON and the way programmers write objects in plain Javascript? Only simple data expressions are allowed on JSON, no functions no comments
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? Brother Jacques needs a proper data structure to store and manipulate data sets, and use methods to maintain and operate objects and its properties.

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

  3. What are properties in Javascript? 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. Which values do not have properties?
    null and undefined

  5. How can we access properties in a value (two ways)?
    using dot operator(access or gives/provides actual value contained by the properties of the object) or square brackets (using square brackets tries to evaluate the expression x and uses the result, converted to a string, as the property name).

  6. What are methods? Methods are properties that hold function values. These are special kinds of functions that only work on the value they belong to.

  7. What are objects? An object is a collection of properties, and a property is an association between a name (or key) and a value. A property’s value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects too.

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

  9. How do you define an object? You may think of objects as octopuses with any number of tentacles, each of which has a name tattooed on it.
    For ex: let objectA = {a: 1, b: 2};
    Object.assign(objectA, {b: 3, c: 4});
    console.log(objectA);
    // → {a: 1, b: 3, c: 4}

  10. What can you say about the mutability of Javascript objects? In JavaScript, only objects and arrays are mutable, not primitive values. (You can make a variable name point to a new value, but the previous value is still held in memory. Hence the need for garbage collection.) A mutable object is an object whose state can be modified after it is created.

SECOND PART:

  1. Why can’t you add new properties to a string variable?
    Because strings are immutable.

  2. What are rest parameters?
    Rest parameter is an improved way to handle function parameter, allowing us to more easily handle various input as parameters in a function. The rest parameter syntax allows us to represent an indefinite number of arguments as an array. With the help of a rest parameter a function can be called with any number of arguments, no matter how it was defined.

  3. (Feel free to skip the sub-chapter of Math object and Destructing) :+1: :slightly_smiling_face:

  4. What is serialisation and what is a use case of serialisation of data?
    The process whereby an object or data structure is translated into a format suitable for transferral over a network, or storage (e.g. in an array buffer or file format). In JavaScript, for example, you can serialize an object to a JSON string by calling the function JSON.stringify().

  5. What is JSON?
    JavaScript Object Notation is a serialisation format widely used for data storage and communication.

  6. What are the differences between JSON and the way programmers write objects in plain Javascript?
    The syntax of JSON was inspired by the JavaScript Object Literal notation, but there are differences between them. For example, in JSON all “keys” must be quoted, while in object literals this is not necessary:

// JSON:
{ “foo”: “bar” }

// Object literal:
var o = { foo: “bar” };

1 Like
  1. Why can’t you add new properties to a string variable?
  • Because a string is a primitive data type.
  1. What are rest parameters?
  • A rest parameter is three dots that is added to a function’s last parameter and they are bound to an array. This allows a function any number of arguments.
  1. (Feel free to skip the sub-chapter of Math object and Destructing)
    Skipped

  2. What is serialisation and what is a use case of serialisation of data?

  • The process of translating a data structure into a transferable format.
  1. What is JSON?
  • JSON is used for data storage and communication format. You can convert any data to JSON format by calling the function below:
    JSON.stringify()
  1. What are the differences between JSON and the way programmers write objects in plain Javascript?
    JSON syntax is independent from JS.
1 Like

Hi @Henk1,

Some really good answers here! :ok_hand:

To answer your question about mutability…

If something is mutable it means it can be changed. Here we are talking about whether a value can be changed in JavaScript. To change a value we would need to either modify its properties, delete whole properties from it, and/or add new properties to it i.e. change its contents. We can do any of these things with the properties of JavaScript objects (including arrays), so we can say that they are mutable.

One interesting aspect to the mutability of JavaScript objects is that, even if two separately defined objects have exactly the same name/value pairs for properties, they will still have separate identities and, when compared, will evaluate as being unequal to each other. This is because they have the potential to have their contents changed in different ways to one another. For this to be possible they must be separate entities e.g

let object1 = {name: "thing", weight: 48, mutable: true};
let object2 = {name: "thing", weight: 48, mutable: true};

console.log(object1 === object2);   // => false

In contrast, strings, for example, are immutable, and so two identical strings are actually one and the same value, and will therefore evaluate as being equal to each other e.g.

let stringA = "immutable";
let stringB = "immutable";

console.log(stringA === stringB);   // => true

Yes…and each property is a key/value pair: it has a value assigned to a name (the key), in a similar way to a variable, but with different syntax.

You’ve got the right idea, but be careful about using the word attribute with objects. Objects contain properties which, as you say, can have values of different data types. Attributes are something that HTML tags can have, and which hold additional information about an element’s content.

Just let us know if you need any further explanations of any of the concepts introduced in this assignment — it was a really long one! :sweat_smile:

1 Like

Hi again @Henk1!

Part 2

Yes :+1: and all primitive data types are immutable.

Even so, the way objects are written in JSON and plain JavaScript is largely the same, except that 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);
(iii) no functions/methods are allowed; and
(iv) no comments are allowed.

1 Like

Hi @cincinnato,

Part 1

Not really… we do use curly braces when defining both objects and functions, but a function also has a function header (which includes its parameters) before the curly braces, whereas an object doesn’t. Also, other types of definition in JavaScript don’t require curly braces e.g. arrays and variables. We can demonstrate more accurately how an object is defined, as follows:

let objectName = {             // properties wrapped in curly braces
    propertyName1: value,      // each property = key/value pair
    propertyName2: value,      // key:value, separated by colon
    "Property Name 3": value,  // key/value pair ends with a comma
    propertyName4: value       // but comma optional after final property
    // etc.
};

… and specifically, it’s an object’s contents (its properties) that can be modified.

Part 2

… and a use case?

That’s right :+1:… and all property names must be written within double quotes; and double quotes must be used for all string values (i.e. no option to use single quotes).

1 Like

Noted. Thanks jon_m! :grinning:

1 Like

Hi @Nityam_Jigyasu!

Great answers with some really nice detail :+1:

Did you miss out this question by accident, or did you not understand it? Let us know if you need further clarification.

Exactly right :+1:… there are a few more differences too, for example:

  • double quotes must be used for all string values (i.e. no option to use single quotes);
  • no functions/methods are allowed; and
  • no comments 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?
  • Until now we were mainly programming with simple data types like strings, numbers etc. In this chapter we are being introduced to objects and arrays that introduce us with basic data structures that will allow us to build more complex structures and group values.

  1. What variable type can be used in order to solve the problem of storing multiple values?
  • Objects and arrays.

  1. What are properties in Javascript?
  • When we create a binding for example, and assign it some value, this value becomes the property of that binding value. For example we can use someValue.lenght to access the lenght property of the value someValue.

  1. Which values do not have properties?
  • Undefined and null.

  1. How can we access properties in a value (two ways)?
  • By writing value.x or value[x].
    But this will not necessarily access the same property. Depending on how the x is interpreted. When using a dot word after, a dot is the literal name of the property… But when using a square brackets the expression between them is evaluated to “get the property name”.

  1. What are methods?
  • Methods are properties that contain functions.

  1. What are objects?
  • Objects are values that are arbitrary collection of properties.

  1. 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)?
  • They can contain many properties with many values, they can be more complex and easier to reach a specific data.

  1. How do you define an object?
  • An object is a value that holds another data in it . I like the well explained octopus-like descprition of objects in the book or like bags in recent video about Javascript. But i do see them as as piece of data that can contain more data in it.

  1. What can you say about the mutability of Javascript objects?
  • It is interesting that objects area bit different than what we have learned so far, they can have different properties, but have the same name. We can have 2 objects sharing the same name but pointing at different properties…


    SECOND PART:

  1. Why can’t you add new properties to a string variable?
  • The string variable is not actually an object so we can’t add new properties on them, such values are immutable and cannot be changed.

  1. What are rest parameters?
  • The rest parameters are bound to an array, which contains all further arguments. This allows funcions to allow any number of arguments. To add a rest parameter we use three dots before the functions last parameter.

  1. (Feel free to skip the sub-chapter of Math object and Destructing)
  • Thanks :stuck_out_tongue:

  1. What is serialisation and what is a use case of serialisation of data?
  • Searilization is converting the data’s all adresses and values etc. into a flat description that can be stored as such for later or sent to someone with ease. :slight_smile:

  1. What is JSON?
  • JSON is Javascript object notation. It is searilization format.

  1. What are the differences between JSON and the way programmers write objects in plain Javascript?
  • JSON looks similar to Javascripts way of writing arrays and objects with few restrictions.
  1. All property names have to be surrounded with double quotes “”.
  2. Only simple data expressions are allowed ( no function calls, bindings or anything that involves actual computation), comments are not allowed either.
1 Like

A: logging in different variables at the same time that may not have the right response to what he is looking for so he would need to just keep a large database that is in order to test many possibilities of why this happens to him

A: Arrays

A: properties are values of wht you are trying to express in a function

A: null and undefined

A: with a dot and with square brackets

A: Properties that contain functions are generally called methods of the value

A:Values of the type object are arbitrary collections of properties.

A:it can group values togather to help define what the function var is looking for

A: One way to create an object is by using braces as an expression then find a property that fills the object

A: objects can change as long as the vale of what is changing is binded to the same value of what is bening changed

A1: values are immutable and cannot be changed.

A2: the rest parameter is bound to an array containing all further arguments

A4: data storage and communication format on the Web, even in languages other
than JavaScript.

A5: serialize the data. That means it is converted into a flat description. A popular serialization format is called JSON

A6: simple data expressions are allowed—no function calls, bindings, or anything that involves actual computation. Comments are not allowed in JSON

1 Like

PART 1

  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 that strings and integers can only store one type of data/values, while an array can store multiple types of data/values.
  2. What variable type can be used in order to solve the problem of storing multiple values?
    An array
  3. What are properties in Javascript?
    It is an association between a variable and an expression that describes it in some way. It tells us something about that variable.
  4. Which values do not have properties?
    Null and undefined
  5. 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. For example value.x or value[x]. Using value.x makes you access the property x of value. For example value.length gives you the length of value, value.color gives you the color of value. When using brackets, what is between the brackets is evaluated and uses the result, converted to a string as the property name.
  6. What are methods?
    Methods are properties that contain functions. They are are generally called methods of the value they belong to, as in “toUpperCase is a method of a string".
  7. What are objects?
    An object is a type of array, we know that an array is defined by the square brackets but the Object allows for arrays and other objects to be joined or bound together. It’s best to think of it like a subject of category, sometimes information from different schools of knowledge can be grouped together with other separate schools of knowledge, because we are crossing the boundaries and forcing these different types of data to exist together we need a more complex form of an array, this type of array is an object and it is defined by {} not square. The major benefit of this is that it can be passed as a complete package from one program to another and transformed into different languages to allow for cross platform integration.
  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)?
    They can store multiple properties like activities, booleans, etc.
  9. How do you define an object?
    Define a variable and defining its properties inside square brackets or after a period.
  10. What can you say about the mutability of Javascript objects?
    Objects can be change their properties if they aren’t immutable.
    Part 2
  11. Why can’t you add new properties to a string variable?
    A string is not an object so it doesn’t have the ability to store new properties.
  12. What are rest parameters?
    Rest parameters allows us to represent any number of arguments as an array.
    3.(Feel free to skip the sub-chapter of Math object and Destructing)
  13. What is serialisation and what is a use case of serialisation of data?
    Data converted into a flat description.
  14. What is JSON?
    JSON stands for JavaScript Object Notation and is a popular serialisation format used for data storage and communication on the web.
  15. 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.
1 Like

Part 1
1 - The part when you need to correlate one event to a series of others.
2 - An array.
3 - It is an aspect of a value like the length of a string, an index array, or mathematical properties in Math. (min, max, etc…).
4 - Null and undefined
5 - Either with a dot like Math.min or square brackets like word[3]
6 - Functions that modify strings or arrays.
7 - I would describe objects as a set of attributes
8 - You can set them arbitrarily, set descriptions for each of them with “”.
9 - A bag of properties with a tag on it: the object
10 - Two objects that have the same value are not considered the same unless they are clearly coded as such.

Part 2

1 - Because it’s not an object
2 - it’s a parameter that’s an array
3 - ok
4 - Serialization means converting data into a flat description. It is what JSON does.
5 - JavScript Object Notation. It’s code for data storage and communication format.
6 - It’s shorter to write but functions, bindings and computation don’t work.

1 Like

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

Carlos Z.

1 Like
  1. large sets of data having multiple values

  2. arrays

  3. These define some characteristic about the values in a data structure, such as the length of an array or the index of a value.

  4. Null and undefined are the exceptions that do not have properties.

  5. properties in a value can be accessed either by using a dot or square brackets

  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 special as they are able to hold as many different datatypes as needed

  9. A collection of values in a list contained within braces

  10. The mutability of Javascript objects means that the values they contained can be changed. This is different to other datatypes such as strings, which will always keep the same value it was defined with.

  11. strings are immutable

  12. These are denoted by a function’s last parameter with 3 dots before its name and are useful for functions that accept any number of arguments.

  13. Serialisation is converting data stored in memory into a flat description of what that data is. It is useful for when we want to do things like saving the data to a file or transferring it to another computer on a network.

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

  15. All property names need to be surrounded in double quotes and only simple data expressions are allowed. So no function calls, bindings, or anything that involves actual computation. Also, comments are not allowed in JSON.

1 Like