Data Structures (Arrays and Objects) - Reading Assignment

Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as string or integers?

  • Variable types like strings and integers can only hold a single type of data, and data structure is needed that is capable of storing multiple values and datatypes to keep everything organized.

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

  • ​You can use array data sets to solve the problem of storing multiple values.

What are properties in Javascript?

  • A few suspicious looking expressions like “myString.length” (to get the length of a string) and “Math.max” (the maximum function) are expressions that access a proper of some value.

  • In the first case, we access the “length” property of the value in “myString”, in the second, we access the proper named “max” in the “Math” object (which is a collection of mathematics-related constants and functions)

  • Almost all of JavaScript values have properties, except null and undefined.

  • The two main ways to access properties in JavaScript are with a dot and with square brackets .

  • E.g. value.x fetches the property of value named “x” — value[x] tries to evaluate the expression “x” and uses the result, converted to a string , as the property name.

  • The elements in an array are stored as the array’s properties, using numbers as property names.

  • The length property of an array tells us how many elements it has.

Which values do not have properties?

  • Null & undefined.

How can we access properties in a value (two ways)?

  • ​.x & [x].

What are methods?

  • ​Properties that contain functions are generally called methods of the value they belong to, as in “toUpperCase” is a method of a string,

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

What are objects?

  • Values of the type object are arbitrary collections of properties, one way to create an object is by using braces as an expression.

  • Inside the braces, there is a list of properties separated by commas. Each property has a name followed by a colon and a value.

  • When an object is written over multiple lines, indenting it helps with readability.

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

How do you define an object?

  • ​Object are like variables that are containers for data values, but objects can contain many values.

  • The values are written as name:value pairs (name and value separated by a colon)

  • The name:values pair in JavaScript objects are called properties:

— Property

— Property Value

  • The object class represents one of JavaScript’s data types, used to store various keyed collections and more complex entities.

What can you say about the mutability of JavaScript objects?

  • ​Objects work differently than value types like (numbers, strings, and booleans which are immutable).

  • You can change their properties, causing a single object value to have different content at different times.

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

  • ​Value of type string, number, and Boolean are not objects, and though the language doesn’t complain if you try to set new properties on them, it doesn’t actually store those properties, they are immutable.

What are rest parameters?

  • ​Rest parameters allow functions to accept any number of arguments.

  • To write such a function. You put three dots before the function’s last parameter.

  • When such a function is called, the rest parameter is bound to an array containing all further arguments.

What is the serialization and what is a use case of serialization of data?

  • ​Serialization means to convert an object into that string.

  • It’s use case is being able to save the data to a file or for transferring it to another computer on the network.

What is JSON?

  • ​The JSON object contains methods for parsing JavaScript Object Notation and converting values to JSON.

  • It can’t be called or constructed, and aside from its two method properties, it has no interesting functionality of its own.

  • JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null.

  • 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

Think about the following questions:

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?

  • strings and integer used for a single type of data, what is needed is a more ‘dynamic’ variable which can hold multiple values and datatypes.
  • this way there can a organised structure to hold all the different data together

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

  • Arrays allow us to group values is a sort of list

What are properties in Javascript?

  • properties a valid name bindings
  • the .length is a example of the property length
  • properties is extra functionality whech can be used ( .color or .length)

Which values do not have properties?

  • The only exceptions are null and undefined (null.length; → TypeError: null has no properties)

How can we access properties in a value (two ways)?

  • 2 ways are by “dot” => value.length or by valid binding name => value[“length”]

What are methods?

  • methods are often called functions of a value it contains, methods returns the ‘function’ value when called

What are objects?

  • object are arbitrary collections of properties which can be accessed by the “dot” followed by the propertie name

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

  • Th problem it solves that object can hold all the different var types together

How do you define an object?

  • example of howto create a objectA > let objectA = {a: 1, b: 2};

What can you say about the mutability of Javascript objects?

  • strings, and Booleans, are all immutable it is impossible to change values of those types
  • Objects you can change their properties, causing a single object value to have different content at different times

Think about the following questions:

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

  • string values are immutable and cannot be changed. But string types do have built-in properties

What are rest parameters?

  • Rest parameters are bound to an array,which contains all further arguments.
    functions can allow any number of arguments.
    for example to add a rest parameter use three dots before the function’s last parameter.

    let numbers = [5, 1, 7];
    console.log(max(…numbers));
    // → 7

(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 converting different types of (object) data pieces existing in memory of the computer into a flat description.

What is JSON?

  • JSON stands for JavaScript Object Notation, it is a popular serialization format.
  • It is widely used as a data storage and communication format on the Web

What are the differences between JSON and the way programmers write objects in plain Javascript?

  • JSON property names have to be surrounded by double quotes
  • JSON has no function calls, bindings, or anything that involves actual computation

JSON Example :
{
“squirrel”: false,
“events”: [“work”, “touched tree”, “pizza”, “running”]
}

1 Like

The weresquirrel sub-chapter introduced the idea of that data is often collected in sets, like the daily observations recorded in a journal. To work with collections of data, a new data structure was introduced, arrays, which are a type of data structure that is made to store information using both integers and strings. Arrays allow us to work with more complex ideas so that we can better assess and present data. Multiple values can be stored in arrays so we can work with data sets instead of individual variables.

In Javascript properties are like characteristics of an array. Using a property will let us get information about the array, for example the number of items in the array by array.length, length being the property.

The values undefined and null have no properties in Javascript.

Dot notation and the numerical index can be used to access properties in a value. Index refers to the ‘member number’, if you will. The first value added to an array is given the index of zero and it would be accessed by stating the name of the array followed by square brackets containing the index number, like so: arrayName[0]. Strings and expressions can also be inside the square brackets. A string would be used to represent the property name and an expression is evaluated to get the array index. Array[14/2] would retrieve the 8th item with index of 7. Dot notation uses a period in between the array name and a (string) property name, like so: arrayName.propertyName.

Methods are functional properties. Several methods exist in Javascript to work on the values in arrays, like toUpperCase() and toLowerCase() which modify the capitalization of strings or push() and pop() which add or remove values from the end of an array, respectively. W3schools shares a list of array methods for us to learn: https://www.w3schools.com/jsref/jsref_obj_array.asp.

Objects are sets of properties. An object is defined using curly braces to surround a list of properties with their values. Each property is specified by name, then a colon, :, followed by the value(s) of that property. Properties in an object are separated by commas. We can retrieve the properties in an object with Object.keys({object goes here}), which returns the object property names as an array of strings.

Objects help us to work with more complex data than integers and strings. Strings and integers are immutable, meaning they don’t change. The number 3 is still the number three more matter how you write it, just as the string “donkey” can’t be altered to something else and still be called ‘donkey’. Objects are mutable, meaning they can change and that is a main benefit to them.

Rest parameters are like placeholders that represent any number of arguments. A rest parameter is signified by three dots leading the name of the last parameter passed to a function. The rest parameter acts as a binding to an undefined number of arguments via an array. Rest parameter also returns an array that can be used in all array methods. Nice examples to see how it’s used: https://www.geeksforgeeks.org/javascript-rest-operator/

Serialisation is a way of converting objects to text in such a way that the data structure and the data are both represented. We need to use a text format for storing information or transporting it over a network. The main use case of serialization of data is sending data to servers and receiving data from servers, so it’s for communication over the Internet.

JavaScript Object Notation, JSON, is a standardized way of describing data. The same format is used in languages other than Javascript as a means of data storage and communication on the Web. Property:value pairs are comma-separated inside curly brackets. Objects and arrays can be represented as values by using curly braces for objects and square brackets for arrays. Differently from JavaScript all property names and string values must be double-quoted.

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?
Collections of data
2.What variable type can be used in order to solve the problem of storing multiple values?
Objects
3.What are properties in Javascript?
Standard features associated with values that can be used to address facts avout the values,
example string.length
4.Which values do not have properties?
5.How can we access properties in a value (two ways)?
. notation or [ ] notation
6.What are methods?
standard functions that are properties, that can be accessed for information about values
7.What are objects?
Data structures, collections of 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)?l
Grouping values together that for a specific task belong together
9.How do you define an object?
Object name, curly brackets around values in the collection.
Inside the brackets, there is a list of properties separated by commas.
10.What can you say about the mutability of Javascript objects?
Data structures that don’t change are called immutable or persistent. Per definition every object can
changed in Javascript, hence they are mutable, however, they can be protected if this is desired.

Now you’ve probably come to the sub-chapter called The lycanthrope’s log. Skip this chapter if you want as it for some reason introduces a lot of math which is completely unnecessary at this point.So feel free to jump to the sub-chapter called Strings and their properties.

2nd part

1.Why can’t you add new properties to a string variable?
Almost all JavaScript values have properties and methods.
These are part of the standard example: string.length is a property
Properties that contain functions are generally called methods of the value
they belong to, as in “toUpperCase is a method of a string”.
2.What are rest parameters?
A three-dot notation to call a function with an array of arguments.
When such a function is called, the rest parameter is bound to an array containing all further arguments.
If there are other parameters before the …, their values aren’t part of that array.
When, as in max, it is the only parameter, it will hold all 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?
    Serialize data means to convert into a flat description, such as CSV, JSON, Ascii, etc.
    5.What is JSON?
    JSON (pronounced stands for JavaScript Object Notation,
  3. 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
  1. The need to record information in the combination of different variables.
  2. An array
  3. Properties are additional binding that associated with a value that hold values .
  4. null and undefined
  5. Through either dot notation that names a property directly ie, string.length
    or using [ ] notation that evaluates an expression to look for a property ie, string["length"]
  6. A method is a property which holds a function as its value.
  7. Object is a data structure usually in an combination of variables and/or functions.
  8. Objects help solving problem related to set of multiple variable and functions. For example, an unit of object can hold data in boolean, integer, string and function, so that we can manipulate these set of data.
  9. It can be defined by curly brackets { }. When inputting object elements, we can type name: value.
  10. Objects allow us to change their properties, causing a single object value to have different content at different times.

Second Part

  1. It is immutable.
  2. A parameter that can hold any number o arguments.
  3. N/A
  4. Serialization is data that converted into a flat description. Use case such as JSON.
  5. JSON is a popular serialization format, it is widely used as a data storage and communication format on the Web, even in language other than JavaScript.
  6. JSON looks similar to JavaScript’s way of writing arrays and objects with a few restrictions. All properties names have to be surrounded by double quotes, and 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?
Multiple pieces of data in one structure
2. What variable type can be used in order to solve the problem of storing multiple values?
Arrays
3. What are properties in Javascript?
A JavaScript property is a characteristic of an object, often describing attributes associated with a data structure.
4. Which values do not have properties?
Null & Undefined
5. How can we access properties in a value (two ways)?
With a dot or 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)?
Mutability
9. How do you define an object?
Inside curly brackets
10. What can you say about the mutability of Javascript objects?
Javascript objects are mutable, opposed to strings, numbers and booleans which are not.

SECOND PART:

1. Why can’t you add new properties to a string variable?
They’re immutable they can not have two different definitions
2. What are rest parameters?
It allows an array to accept any number of arguments
4. What is serialisation and what is a use case of serialisation of data?
Serialisation is when data is converted into a flat description. use case would be, to save data in a file or send it to another computer over the network
5. What is JSON?
JSON is a serilaisation format that is used for many languages including Javascript
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
They use double quotes, not single

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?

For having a view on the conditions that triggers some behavior (transforming into a squirrel), it is necessery to have a data structure. For that we need to build more complex structures by using objects that groups values as strings (a higher form of complexity).

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

A data type witch is called ‘array’

3 What are properties in Javascript?

Properties are the values associated with a JavaScript object.

4 Which values do not have properties?

‘Null’ and ‘undefined’

5 How can we access properties in a value (two ways)?

‘Value.property’ (example: Math.max) or ‘value[property]’ (example: an array)

6 What are methods?

Methods are functions stored as object properties of the value they belong to.

7 What are objects?

A Javascript object is a collection of unordered 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 create more plasticity to code so it can solve more complex problems. Object values can be modified.

9 How do you define an object?

Example:

Let objectLight = {green: true, red: false};

Console.log(objectLight.green);

// --> true

10 What can you say about the mutability of Javascript objects?

Object can change their properties, causing a single value to have different content at different times.

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

Because a string variable is one of the 5 primitives. You can only add new properties to objects. You solve this problem by wrapping up the string variable into an object.

12 What are rest parameters?

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

13 What is serialisation and what is a use case of serialisation of data?

Serialisation is a way to send over code through a network, so users of that network can easely use the code. The data need to be converted into a description before sending it. The receiver can deconvert it back into Javascript language and work with it. An important usecase is opensource software development.

14 What is JSON?

JavaScript Object Notation is a serialization format that is widely used as a data storage and communication format on the Web for several program languages.

15 What are the differences between JSON and the way programmers write objects in plain Javascript?

JSON is restricted in his use. All property names have to be surrounded by double quotes, and only simple data expressions are allowed. Not even computation or comments.

2 Likes

FIRST PART

  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?

Use of strings to store data will become awkward and inefficient, because you need somehow extract the digits and convert them to number to access them.

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

Array are perfect for storing sequences of multiple values.

  1. What are properties in Javascript?

Most Javascript values have properties.

  1. Which values do not have properties?

They are null and undefined

  1. How can we access properties in a value (two ways)?
property.x 
value[x]
  1. What are methods?

They are properties that hold function values.

  1. What are objects?

Objects are arbitrary collection of properties. To create them you need use braces as an expression.

  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 value of different types as integer, string, array, boolean etc.

  1. How do you define an object?

A list of properties separated by commas, enclosed in braces.

  1. What can you say about the mutability of Javascript objects?

That few types of values as numbers, strings and Boolean are immutable.
Objects values can be modified.

SECOND PART:

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

Because values type string, number and Boolean are not objects and they are immutable.

  1. What are rest parameters?

Rest parameters are bound to an array,which contains all further arguments. To add use three dots before the functions last parameter.

  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. It is useful for saving, storage and transfer of data.

  1. What is JSON?

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

  1. What are the differences between JSON and the way programmers write objects in plain Javascript?

All property names need to be surrounded by double quotes.
Only simple data expressions are allowed - nothing what involves actual computation.

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?
    He need to store big sequences of data.

  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 the elements of an array or an value.

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

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

  6. What are methods?
    It is properties that contain functions.

  7. What are objects?
    It is collections of properties/elements.

  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)?
    It solves the need for storage of more amount of values.

  9. How do you define an object?
    A collection of properties.

  10. What can you say about the mutability of Javascript objects?
    They are mutable, which means that its possible to change the properties and single object values. Compared to the smaler values, whish are immutable.

Now you’ve probably come to the sub-chapter called The lycanthrope’s log. Skip this chapter if you want as it for some reason introduces a lot of math which is completely unnecessary at this point. So feel free to jump to the sub-chapter called Strings and their properties.
Think about the following questions:

  1. Why can’t you add new properties to a string variable?
    Because a string is not an object. It will not store the the property you try to add.

  2. What are rest parameters?
    It allows us to represent an indefinite number of arguments as 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 the tangles of memory, that arrays with arrays inside represents, to a flat structure, that can be saved in a file and send over the network.

  5. What is JSON?
    Its a popular serialisation format that looks similar to javascript.

  6. What are the differences between JSON and the way programmers write objects in plain Javascript?
    In json all property names have to be surrounded by dobbelt quotes and only simple data expression is allowed and 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?
    problem is collection of data -
  2. What variable type can be used in order to solve the problem of storing multiple values?
    solution is new data structure - arrays ex: let array = [value, value2];
  3. What are properties in Javascript?
    characteristics of a value
  4. Which values do not have properties?
    null and undefined
  5. How can we access properties in a value (two ways)?
    using . or [ ]
  6. What are methods?
    a property that contains a function. these particular functions do not require any arguments
  7. What are objects?
    arbitrary collections of properties. often multiple lists being stored within an object
  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 hold multiple different types of data together
  9. How do you define an object?
let object = {itemOne:"Apple", itemTwo:"Orange"};
  1. What can you say about the mutability of Javascript objects?
    objects are different because you can change their properties, which can cause an object value to change at different times

SECOND PART:

  1. Why can’t you add new properties to a string variable?
    string values are immutable
  2. What are rest parameters?
    parameters that accepts any number of argument
  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?
    a flattened way of transmitting data that is stored in memory
  5. What is JSON?
    Javascript Object Notation - a serialization format used on the web for javascript and some other languages
  6. 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. Comments are not allowed in JSON.
1 Like

Part 1

  1. The problem introduced in this sub-chapter is the need to store multiple values and data types and be able to work with them thus requiring a more complex data structure than that of simple string and integer variables that can’t handle multiple types of data simultaneously.

  2. JS provides a data type called an array that is used for storing sequences of values.

  3. properties are expressions that access a property of some vale.

  4. “null” and “undefined” are values that don’t have properties in JS.

  5. we can access properties in JS using a dot ( . ) or square bracktes ( [ ] ).

  6. Methods are properties that contain function.

  7. objects are a collection of properties.

  8. objects can hold an arbitrary collection of properties that allow them to group and hold different types of data in one place.

  9. to define an object we use braces as an expression; inside these braces there is a list of properties separated by commas and each property has a name followed by a colon and a value.

  10. Objects in JS can change their properties, causing a single object value to have different content at different times.

Part 2

  1. because they are immutable, thus it is impossible to change values of those type.

  2. The rest parameter (…) is a syntax in JS it allow a function to be called with any number of arguments.

  3. felt free.

  4. serialization is the process of converting data into a flat description, it can be used for saving data in a file for later or sending it to a another computer over the network.

  5. JSON stands for JavaScript Object Notation, which is a popular serialization format used as a data storage and communication format on the web over multiple programming languages.

  6. Unlike JavaScript in JSON all property names have to be surrounded by double quotes and only simple data expressions are allowed, no function calls, binding or anything that involves actual computation,further comments are not allowed in JSON.

2 Likes

Part 1

  1. The sub-chapter called “The Weresquirrel” introduces the problem of storing multiple types of data in strings or integers. Our squirrel-friend needs a data structure that is capable of storing multiple values and datatypes to keep the information in his diary organized.
  2. To store multiple values, you can use arrays.
  3. Properties are sub-values that define characteristics about values of a data type. Different data types have different default properties. For example String.length gives you the length of any string. You can also define your own properties for values, when you make objects.
  4. Null and undefined do not have properties.
  5. There are two ways to access properties in a value. The first way is to use a dot, for example value.property. The other way is to use square brackets, for example value[“property”].
  6. Methods are properties that hold functions as their values. These can be called on the values that own the method.
  7. Objects are data structures that allow us to store arbitrary collections of properties in a key:value manner.
  8. Objects can be used to store all the other data types in an orderly way.
  9. Objects are defined with let, const or var, and with braces. Example: var Object = {key: value}
  10. JavaScript values, such as numbers, strings and booleans are immutable. That means that you cannot change thieir value without creating an actual new physical bit value in the computer’s memory. Objects are immutable, and can be changed without creating new bit values. This means that you can change an objects properties so it has different content at different times.

Part 2

  1. You cannot add new properties to a string value, because it is a primitive data type and is immutable.
  2. Using rest parameters is a way to make a function accept any number of arguments. When using rest parameters, you use three dots before the argument. For example: Math.max(…anyNumbers). anyNumbers can be a list of many numbers, and the individual number values of the list will be passed into the function as arguments automatically.
  3. Serialization is storing data in a format so that the data can be easily read by other computers. In JavaScript, objects and arrays are stored in the computer’s memory as bits holding the addresses of their contents (their place in memory). This means that in order to send these objects and arrays to another computer requires us to either send our whole computer memory (which does not make sense) or to serialize the data (converting it to a flat description that all computers easily can read) using for example JavaScript Object Notation (JSON).
  4. JavaScript Object Notation (JSON) is a serialization format widely used for data storage and communication between computers.
  5. The way to write objects and arrays in JavaScript and JSON is similar. The difference is that in JSON, all property names have to be surrounded by double quotes, and nothing that involves actual computation is allowed in the objects/arrays (functions, bindings etc.). No comments are allowed either.
2 Likes

[quote=“ivan, post:1, topic:3116”]

  • 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 fact that he is turning into a esquirrel but tracking the daily data of what he is doing, gives a more detailed solution, that can be use on a program to aproach solutions

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

  • What are properties in Javascript?
    " These are expressions that access a property of some value"

  • Which values do not have properties?
    “Exceptions are null and undefined . If you try to access a property on one of these nonvalues, you get an error.”

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

  • What are methods?
    “A number of properties that hold function values.”

  • What are objects?
    “Are arbitrary collections of properties. One way to create an object is by using braces as an expression.”

  • 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)?
    “Object tie different properties together to express a single condition. This allows programmers to better represent how a system should behave.”

  • How do you define an object?
    “Using braces as an expression.”

  • What can you say about the mutability of Javascript objects?
    Users can change objects properties.

SECOND PART:

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

  2. What are rest parameters?
    Rest parameters are bound to an array,which contains all further arguments. This allows functions to allow any number of arguments.

  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?
    Serialization converts data into a flat description of itself

  5. What is JSON?
    “JavaScript Object Notation. It is widely used as a data storage and communication format on the Web, even in languages other than JavaScript.”

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

2 Likes
  1. This problem requires Jacques to be able to store multiple values in the same variable and then be able to access them at a later date. Simpler variable types like strings and integers are not built for this as they can only access their built-in properties (i.e., string.length).

  2. Array

  3. Properties are the values that are assigned as characteristics of an object in Javascript.

  4. null and undefined

  5. We can use “.” or [ ]. We use “.” if we know the exact name of the property and it is a valid variable name. Otherwise, we use [ ].

  6. Some value types have properties that refer to functions. These functions are called methods and they apply some kind of operation to the value.

  7. Objects are data structures that are collections of properties.

  8. Objects can hold a variety of custom properties that represent any kind of data type.

  9. var myObject = {propertyName: value, propertyName2: value2};

  10. Object values are not immutable, as they can be changed.

SECOND PART:

  1. You can’t add new properties to a string variable because they already contain their own built-in set of properties which are immutable.

  2. Rest parameters are represented by three dots (…) before the final parameter in a function. They indicate that any number of arguments may be passed to the function. Any additional arguments are put into an array and referenced by the rest parameter.

  3. Serialization is the flattening of data, allowing it to be easily transferred over a network.

  4. JSON (Javascript Object Notation) is a widely used serialization format consisting of name:value pairs.

  5. In JSON, only allows for simple data expressions like strings and booleans. Also, double quotes must surround property names.

2 Likes
  1. Arrays can store sequences of values. Strings are inefficient for this as you would have to extract digits from string and convert back to numbers to access data.

  2. Arrays can be used to store multiple values.

  3. Properties of JavaScript are expressions that access an aspect of a value. Such as .length or Math.max.

  4. Undefined and null do not have properties.

  5. We can access properties of values with a dot and with square brackets. Value.x or value[x]

  6. Methods are properties that contain functions such as .toUpperCase or .push or .pop.

  7. Objects are collections of properties that are names and values.

  8. Objects allow us to assign and store different types of properties and values to one variable. This cannot be done with other types such as strings, integers, arrays or booleans.

  9. An object is “an unordered collection of related data, of primitive or reference types, in the form of “key: value” pairs. These keys can be variables or functions and are called properties and methods, respectively, in the context of an object.”
    Sourced:GeeksforGeeks.org

  10. Javascript objects are mutable unlike numbers, strings, Booleans. You can change an objects properties to where they have different values at different times.

  11. You cannot add new properties to a string because their properties are immutable and can’t be changed.

  12. Rest parameters are the three dots added to front of parameters that’s allows us to gather any number of arguments into an array and do what we want with them.

  13. Serialization is the process where an object or data is converted into a flat format for data storage or to transfer over a network.

  14. JSON stands for JavaScript Object Notation. A popular serialization format.

  15. In JSON, property names have to have double quotes and only simple data expressions. No comments, function calls, bindings or anything that involves computation.

1 Like
  1. Arrays are a special type of variable that can hold more than one value at a time, strings are a sequence of characters used to represent text rather than numbers.
  2. array
  3. Properties are attributes associated with a data structure managed as key/value pairs. All JavaScript values have properties
  4. The exceptions are null and undefined
  5. The two main ways to access properties in JavaScript are with a dot and with square. value.x and value[x]
  6. methods are properties that contain functions.
  7. object are collections of properties and provide ways to group several values into a single value,
  8. Objects can change their properties, causing a single object value to have different content at different times.
  9. An object initializer is a comma-delimited list of zero or more pairs of property names and associated values , enclosed in curly braces ( {} ). const object1 = { a: a, b: b, c: c };
  10. Numbers, strings, and Booleans, are all immutable it is impossible to change values of those types.
  11. Values of type string, number, and Boolean are not objects, such values are immutable and cannot be changed.
  12. It can be useful for a function to accept any number of arguments.
  13. Objects and arrays are stored in the computer’s memory If you want to save data in a file for later or send it to another computer over the network, you have to somehow convert these tangles of memory addresses to a description that can be stored or sent, what we can do is serialize the data, that means it is converted into a flat description.
  14. A popular serialization format is called JSON (pronounced “Jason”), which stands for JavaScript Object Notation. It is widely used as a data storage and communication format
  15. JSON looks similar to JavaScript’s way of writing arrays and objects, with a few restrictions, only simple data expressions are allowed—no function calls, bindings, or anything that.
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?
Variables and String data are limited to one type of value. Jacques needs a database that can store multiple different types of values.

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

3. What are properties in Javascript?
Properties are values associated with a javascript object.

4. Which values do not have properties?
Null and undefined do not have properties in javascript.

5. How can we access properties in a value (two ways)?
You can either you use a dot expression or use square brackets.

6. What are methods?
Methods are properties that contain a function.

7. What are objects?
Objects are containers for named values, called properties and methods.

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 have different types of values that are tied to a condition.

9. How do you define an object?
You can define an object with a value or a method.

10. What can you say about the mutability of Javascript objects?
You can code javascript to be mutable or immutable. Mutability allows an object to be changed in a different part of the code. Immutable does not allow objects to changes in the code. They both have strengths and weaknesses.

SECOND PART:

1. Why can’t you add new properties to a string variable?
String variables are primitive type or single value properties.

2. What are rest parameters?
The rest parameter syntax allows us to represent an unlimited number of arguments as an array.

3. (Feel free to skip the sub-chapter of Math object and Destructing)
OK … I will skim it.

4. What is serialisation and what is a use case of serialisation of data?
Serialisation of data is a process of making the data into a format suitable for sending over a network.

5. What is JSON?
JSON = JavaScript Object Notation. JSON format is text only and can easily be sent to and from a server.

6. What are the differences between JSON and the way programmers write objects in plain Javascript?
In JSON the property values need to be expressed in double quotes. There are also no funtions, no bindings, and no comments. Other then that, it is very similar to plain javascript.

1 Like

Hey guys - I am just trying to wrap my head around objects, properties and values. Could you please confirm that I am thinking correctly:

Object = myWardrobe
Properties = casual, formal, sleeping
values = jeans, dress, pyjamas

var = myWardrobe { 
    casual: “jeans”,
	formal: “dress”
	sleeping: “pyjamas”
	 };

1 Like

Hi @Jody,
Yes your interpretations are spot on ! :slight_smile:
However, your syntax is slightly incorrect. The “=” (equals to ) sign comes after variable name “myWardrobe” . Below syntax is correct –

var myWardrobe = { 
    casual: “jeans”,
	formal: “dress”,
	sleeping: “pyjamas”
	 };

Happy Learning ! :slight_smile:

2 Likes

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?
    Due to the amount of data that needs to be analysed to discover the reason why, we need a data structure that can store a collection of data under one variable.

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

  3. What are properties in Javascript?
    Properties are the values attached to an object

  4. Which values do not have properties?
    null
    undefined

  5. How can we access properties in a value (two ways)?
    Dot (.) and square brackets ([ ])

  6. What are methods?
    Properties that contain functions

  7. What are objects?
    An object is a collection 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 allow us to group values and access them later on

  9. How do you define an object?

var myDay = {
             morning: "cycle",
             afternoon: "work",
             evening: "sleep"
};
  1. What can you say about the mutability of Javascript objects?
    Programmers can change the object properties so that the property values can have different content at different times