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?
you cannot store multiple values in the variable types such as strings and integers
2. What variable type can be used in order to solve the problem of storing multiple values?
array
3. What are properties in Javascript?
properties hold values defining the object the belong to.
4. Which values do not have properties?
null and undefined
5. How can we access properties in a value (two ways)?
dot and square brackets value.x or value[x]
6. What are methods?
they are properties that hold function values
7. What are objects?
they 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)?
they are able to store multiple values of different types
9. How do you define an object?
by defining the properties - inside the braces, there is a list of properties separated by commas. Each property has a name followed by a colon and a value.
10. What can you say about the mutability of Javascript objects?
JavaScript objects are mutable.
SECOND PART:
1. Why canât you add new properties to a string variable?
String variable is not an object and you can add new properties only to objects. You can actually create property in the string but it is not stored.
2. What are rest parameters?
Rest parameter defines that the function can have infinite number of parameters - when the function is called, all specified values are bound to an array
3. (Feel free to skip the sub-chapter of Math object and Destructing)
4. What is serialization and what is a use case of serialization of data?
Serialization is a transformation of object to flat data.
5. What is JSON?
JSON stands for JavaScript Object Notation which is a flat data structure with a specific format. It is commonly used as a data storage type and communication format on the Web.
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
All property names have to have double quotes and only simple expressions and values are allowed - no
computations, no functions or bindings and no comments.
Part 1
q1: basic variable types can only store 1 value at a time without any relation between the values of dirrerent variables. Here we need a logging day by day of what he did that day (activities) + did it trigger the transformation (squirrel true or false).
q2: arrays can be used to help solve this problem. An array letâs us store a list of , in this case, activities.
q3: a property gives us more information about a variable value. For example a string variable âstringvarâ wich contain a value, we can ask the length of that value by using the propery âlengthâ: stringvar.length
q4: the following values do not have properties: null / undefined
q5: with a point or between square brackets: stringvar.length or stringvar[length]
q6: Methods are actions we can call on a variable in the same way we ask for a property. Usually functions that are performed contain the necessary code for that action
q7: Objects can be used to group some properties together to be seen as one âobjectâ.
q8: Inside an object we can define several properties by name and they could be of a different type. For example in our problem: object âDailyLogâ with properties âActivitiesâ (array of all the activities he did that day) and âtransformationâ (boolean value to show if the transformation has been triggered that day)
q9: You define an object by using braces and inside the braces you define a list of properties with a name followed by a colon and a value
q10: We can change the values inside an object. After this action, all objects with the same identity will still be the same when you compare them. Other objects that do not share the same identity but had initially the same values, are not the same anymore since their values did not change.
Part 2
q1:It does not store properties because itâs not an object. We can use the built-in properties on strings (or other data types)
q2:It letâs you accept any number of values as parameters that it will store in an array.
q4:Serialization is to convert data into a flat description so it is easy to send the data over a network to another computer or store it on a computer (=use case) .
q5: Javascript object notation. (datastorage/communication format)
q6: JSON has a few restrictions: double quotes for property names, no comments, no computations (functions, bindings, etc).
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?
Entries canât really be identified by numbers or strings, true and false boolean values would be better to determine whether the squirrel turned or not.
What variable type can be used in order to solve the problem of storing multiple values?
youâd want to use an array.
What are properties in Javascript?
theyâre values that define a characteristic of the element.
Which values do not have properties?
null and undefined properties.
How can we access properties in a value (two ways)?
.name or with []
What are methods?
functions stored as object properties.
What are objects?
variables that can include many values, sort of like containers for values.
What problem do objects solve that cannot be solved with other value types weâve learned so far (such as integer, string, array, boolean etc)?
Objects allow you to store more information into a data structure as opposed to single entity structures.
How do you define an object?
you define a variable and then put the object into curly braces.
What can you say about the mutability of Javascript objects?
theyâre able to be changed where as other properties can not.
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:
Why can't you add new properties to a string variable?
because it is immutable.
What are rest parameters?
⌠they present unknown parameters.
(Feel free to skip the sub-chapter of Math object and Destructing)
What is serialisation and what is a use case of serialisation of data?
its the process of converting an object into a string. It would be for making data structures that can be edited later on.
What is JSON?
Javascript Object Notation. itâs a data storage communication format.
What are the differences between JSON and the way programmers write objects in plain Javascript?
Json doesnât allow you to call functions and doesnât allow comments.
PART I
1. The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Data structures that group different number of values and are able to store this information.
2. What variable type can be used in order to solve the problem of storing multiple values?
An variable type called Array.
3. What are properties in JavaScript?
They are expressions linked to values.
4. Which values do not have properties?
null and undefined.
5. How can we access properties in a value (two ways)?
⢠value.x : x is the property name of value.
⢠value[x]: tries to evaluate the expression x and uses the result, converted to a string , as the property name. Exo: array[âlengthâ] equivalent to array.length.
6. What are methods?
They are properties that hold functions values.
7. What are objects?
Data structures that group different kind of values and 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)?
To store different types of values and work with its properties.
9. How do you define an object?
It is a type o value which is able to store simple types of data, other objects and methods.
10. What can you say about the mutability of JavaScript objects?
We can say that we can change their properties, causing a single object value to have different content at different times.
PART II
1. Why canât you add new properties to a string variables?
Because string is immutable.
2. What are rest parameters?
They allow a function to compute all the arguments bounded to an array of elements. It can be performed with three dots before the name of the arguments set given.
3. What is serialization and what is a use of serialization of data?
It is the way to convert information in a flat description.
4. What is JSON?
JavaScript Object Notation. It is a data storage and communication format on the web for JavaScript and other languages. There are two functions to work with JSON format, JSON.stringify() and JSON.parse().
5. What are the differences between JSON and the way programmers write objects in plain JavaScript?
There are not function calls, bindings, or anything that involves actual computation. Comments are not allowed in JSON neither.
-
weresquirrel problem requires multiple variables to be linked and recorded.
-
Arrays allow this to happen
-
Properties are values associated with an object.
-
Null and undefined objects do not have properties
-
properties can be obtain from obj.property or obj[property]
6.methods are the different actions that can be performed on an object
-
objects are used to create things with common code, with properties and methods.
-
objects can store multiple values and are a more organised way than functions or arrays.
-
objects can be defined as a var only using { } and stating the different properties
-
objects are mutable, allowing to change values when the function is called.
second part
-
string is only designed to hold a single value and immutable
-
rest parameters are present after the defined parameters and stored into an array
-
Serialisation is a data type suitable for communications
-
JSON is Javascript object notation, often used in data storage and communication
6.JSON only uses doible quotes for properties and can only execute simple instructions
PART 1:
1, The weresquirrel needs to store data that cannot fit into a single integer or string. He needs a data structure
so that he can manage his findings better.
2. Arrays can handle multiple values, for example, [1,2,3,4,5].
3. A property is a characteristic/expression of a value. For example, length is a property of an array.
4. The values with no properties are null and undefined.
5. Two ways to access properties are the dot (.) and square brackets [ ] expressions.
6. Methods are the properties that a function contains. For example, a string has a method toUpperCase.
7. Objects are a collection of properties that help to define an object better. For example, an object car can have properties like types of tires, number of doors and if it is an electric car.
8. Objects solve the problem of storing various data types (booleans, integers, strings) into one data type.
9. An object is defined by an object name, curly braces, and, inside, properties separated by commas.
let day1 = {
squirrel: false,
events: ["work", "touched tree", "pizza", "running"]
};
- Objects in JS are mutable. Object properties may be changed as the user needs them to be. As long as they are not const, which makes an object immutable.
-
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?
A string cannot describe all the activities being undertaken as each index in the string is only a character. Bindings change, but are a single value at any moment. An integer cannot provide a change in data per index. This log requires an array of information, to be stored each day, or a collection of strings and integers. -
What variable type can be used in order to solve the problem of storing multiple values?
Arrays -
What are properties in Javascript?
Properties are expressions that access a property of almost all JavaScript value. -
Which values do not have properties?
Null and undefined are the exceptions that do not have properties. -
How can we access properties in a value (two ways)?
To access a valueâs property is by a dot and a square bracket. -
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 eg .push -
What are objects?
Objects are considered collections of properties, inside object the user can store different value types -
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 hold different datatypes that tie different properties together to express a single condition. -
How do you define an object?
Curly brackets are used to create objects. Properties inside the curly brackets are separated by commas. Each property is named, followed by a colon and a value. -
What can you say about the mutability of Javascript objects?
Objects are mutable, however the primitive lives on. Care should be applied to code by remembering this.
Part 2
- Why canât you add new properties to a string variables?
Numbers, strings and Booleans are immutable. - What are rest parameters?
Syntax is ⌠They allow a function to accept any number of arguments - What is serialization and what is a use of serialization of data?
It is the way to convert information in a flat description. - What is JSON?
JavaScript Object Notation. It is a data storage and communication format on the web for JavaScript and other languages. There are two functions to work with JSON format, JSON.stringify() and JSON.parse(). - 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 double quotes, and only simple data expressions are allowed â no function calls, bindings, or anything that involves actual computation. Comments are also not allowed in JSON.
PART 2:
- You cannot add new properties to a string variable because it is not an object. It is immutable.
- Rest parameters allow passing in an infinite number of parameters using the ⌠notation. This operator will group the parameters in an array.
- Skip
- Serialization of data is to flatten out your data and make it easier to use and send it to another computer. This allows other computers to easily read and work with this data.
- JSON is a method to serialize data in JS. The data looks very similar to that of an array.
- All property names have to be surrounded by double quotes,
and only simple data expressions are allowed.
FIRST PART
- Keep record of a log where a series of event lead to a result, thatâs why itâs needed to use an array to list all events and its progression and result.
- Objects and arrays.
- Values that are associated with objects.
-
null
andundefined
have no properties. - Using either the dot syntax as:
something.property
, or the [] syntax as:something[property]
- Properties that contain functions.
- Is a collection of arbitrary properties.
- Create datasets and evaluate relationships between them as shown in the âweresquirrelâ example.
- Like this:
myObject = { firstproperty : value, secondproperty : anothervalue };
- Honestly, that is a bit confusing, since it make references to the object that referred the object that referred the object and so on until one hits data. It makes sense for JavaScript since all its logic revolves around making connections between the functions but can become messy if not handled properly.
SECOND PART
- Strings and most kind of variables donât allow to artificially input new properties.
- Parameters that allow to represent an indefinite number of elements in an array.
- No :v
- Is to convert data into a structure that allows to export to other pc/system easily by making it plain description of what the data was.
- JSON stands for JavaScript Oriented Notation and is a popular serialization to exchange data using JavaScript.
- JSON require the usage of
â â
and not usingâ â
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 to be solved is storing a daily record of actions taken by Jaques.
What variable type can be used in order to solve the problem of storing multiple values?
Arrays can be used to store multiple values.
What are properties in JavaScript?
They are values that belong to data types in JavaScript. For example the length
property on a string value.
Which values do not have properties?
The values that do not have properties in JavaScript are null
and undefined
.
How can we access properties in a value (two ways)?
You can access a property by the dot notation or by the square brackets notation.
What are methods?
Methods are properties that holds function values.
What are objects?
Objects are instances of values that are collections of properties.
What problem do objects solve that cannot be solved with other value types weâve learned so far (such as integer, string, array, boolean etc)?
Objects can represent a more complex data structure with particular properties and methods.
How do you define an object?
One way of defining objects in JavaScript is by grouping properties between curly brackets. For Example:
let activities = {events: ["work", "ice cream", "cauliflower",
"lasagna", "touched tree", "brushed teeth"],
squirrel: false}
What can you say about the mutability of JavaScript objects?
Mutability refers to the ability to change objectâs values without changing its identity.
SECOND PART:
Why canât you add new properties to a string variable?
Because the string
data type is inmutable.
What are rest parameters?
The rest parameter âspreadsâ out the array into the function call, passing its elements as separate arguments.
What is serialization and what is a use case of serialization of data?
Serialization is the flat description of data that can be stored and sent over the network.
What is JSON?
JSON 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?
The difference with JavaScript object declarations are that 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.
source: Eloquent JavaScript
Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
The ability to group or create data structures capable of holding different values of different data types.
What variable type can be used in order to solve the problem of storing multiple values?
Objects and Arrays
What are properties in Javascript?
A property can be described like a container that holds values inside an objects
Which values do not have properties?
undefined and null
How can we access properties in a value (two ways)?
Properties can be accessed as followed: objectname.propertyname or objectname['propertyname']
What are methods?
It is some sort of function to manipulate an objects
What are objects?
Objects is a data structure capable of holding different data type with a key linked to a value.
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 hold different datatypes and they also add some sort of organization or structure to the values been held.
How do you define an object?
let Object name {key:value}
What can you say about the mutability of Javascript objects?
mutability is the ability to change properties. Objects are mutable whereas booleans or strings are immutable
SECOND PART:
Why canât you add new properties to a string variable?
because a string are immutable
What are rest parameters?
The rest parameters allows you to call an indefinite values in an array
What is serialization and what is a use case of serialisation of data?
Serialization is the process of converting data structures or an object state into a format that can be stored or sent
What is JSON?
A method for serialization of data
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 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.
- Storing a record of all the events that jacques did during a day in a single binding.
- Object and arrays
- types associated with some value. e.g functions (or methods), variables such as string,number,etc.
- null and undefined
- val.prop OR val[âpropâ]
- methods are functions associated with an object as a property e.g. Math.max() is a method of Math object
- Data structures holding a set of preoperties.
- They can hold custom set of values in the form of properties.
- obj = new Object({<object definition>}) OR obj={<object definition>}
- Objects can change its state after it is made and this is called mutability. Mutability is for arrays and objects.
Second part
- It is immutable
- Any extra parameters passed to a function call can be accessed by assigning them as part of an array in the following manner and this is called rest parameters:
function foo(âŚrest){
return rest;
}
foo(1,2,3,4);
//> [1,2,3,4]
- Serialization means that the data is converted into format suited for stroage e.g. in file or buffer, in the form of bytestream. Use case of serialization: Jsonify a javascript object
- JSON (JavaScript Object Notation) is a format for storing the data in a flat format (string) which is similar to the way objects are represented in Javascript.
- JSON requires its keys to be inside quotes, objects do not.
The values may not contain any computation in them for JSON.
Jacques needs to keep a log of everything he sees and does in a day. This log will have multiple entries in it, which will require data structures such as arrays that can store multiple things.
Values in JavaScript have properties associated with them (except for null and undefined). These properties can be other values, or even functions. You can access properties through the dot notation (myValue.myProperty) or the square bracket notation (myValue[âmyPropertyâ]).
Methods are properties of values that are actually functions that act on that values in some way. For example, âtestâ.toUpperCase() is a function that acts on the âtestâ string to convert it into âTESTâ (uppercase).
An object is a collection of properties. You can add, remove, and change properties of objects at any time. You can use objects to group properties together. You can define an object like:
let myObject = {
"property1": "value1",
"property2": "value2"
}
Strings are immutable. You canât change a string once created.
Rest parameters allow a function to accept any number of additional arguments.
Serialization converts your data into a format that can be stored so that it can be loaded (and then deserialized) later. You may want to do this if you need to send data over a network or store data in a file.
JSON (JavaScript Object Notation) is a common serialization format. It is like a small subset of how programmers make objects in JavaScript. All property names must be strings in JSON, and all property values must be values, not functions or variables.
First part
- The subchapter introduces a problem related to storing different data in one variable
- It is array. An array is a list of values storing between square brackets and separated by commas.
- Almost all values in JavaScript have properties and to access them we use two ways: with dot after value or square brackets.
- null and undefined
- To access the properties we use two ways: with dot after value or square brackets.
- Methods are properties that contain functions
- Objects are collection of properties
- Objects help to store different types of entries (numbers, string, booleans) in one expression
- Objects are defined by grouping properties between braces separated by commas. Each property has a name followed by a colon and a value
let activities = {events: [âworkâ, âcauliflowerâ, âtouched treeâ, âbrushed teethâ], squirrel: false} - Properties of an object can be changed, so the content of the same object can be different at the different time.
Second part
- You cannot add new property to strings because they are immutable. They have only some built-in properties.
- it helps function to accept any number of parameters
- Serialization is a method of converting data into a format which can be stored or sent
- JSON is a popular serialization format stands from JavaScript Object Notation. It is used as a communication format on the Web.
- The differences are : All property names have to be surrounded by double quotes,
and only simple data expressions are allowed
- This chapter introduces data sets (working with a collection of numbers). This is messy to try and do with string.
- Arrays can be used to store multiple values.
- Properties are a specific characteristic of a value, such as .length, that returns the length of a string.
- In Javascript, only null and undefined, do not have properties.
- We can access properties by either using a dot o square brackets: _string.x or string[x]
- Methods are properties that contain functions. They are considered a method for the value that they belong too.
- Objects area a collections of properties the values of which can be changed.
- Objects solve the problem of being able to store multiple properties in one value
- Objects are defined by naming it, followed by braces. Within the braces are lists of properties. Each property is followed by a colon. After the colon is the value. That can be a simple boolean, an array, etcâŚ
- Javascript objects are mutable, meaning that you can change the values. This allows objects the ability to contain different content at different times.
Part II:
- You cannot add new properties to a string variable because it is not an object. It does not store new properties.
- REST parameters allow you to accept multiple arguments. These arguments are bound to an array.
- To serialize data is to convert it to a flat description. Basically this takes the data you want from computer memory and converts them into a usable format (ie: something that can be stored or sent).
- JSON stands for Javascript Object Notation and is a popular serialization format.
- The differences between JSON and plan Javascript are: JSON property names must use double quotes " " and only simple data expressions. No functions or computations. Additionally, comments are not allowed.
- The Problem introduced is storing data as multiple values in a structured and useable way.
- The array variable type can be used to store multiple values.
- Properties are attributes of a value.
- The nonvalues null and undefined.
- With a dot or square brackets value.x or value[x]. With access by dot like value.x the value after the dot is fetched, evaluated, interpreted as a string and used as property name. With square brackets like value[x] the string inside the brackets is used as property name.
- Methods are properties, which contain functions.
- Objects are values which have arbitrary collections of properties.
- Objects can hold different kind of datatypes
- One way to create an object is to use braces: objectName{ propertyOne : false, propertyTwo : [arrayElement1; arrayElement2]};
- Mutability means, that the object values can be modified and have different values at different times. The values of an object can be accessed seperately from other code. Whereas values from the type number , boolean or string are immutable. They can not changed outside its value and get changed from outside code.
- New properties will not stick. A string is not an object, which you can add properties. Strings are immutable.
- Rest parameters give a function the possibility to take several arguments. The Rest parameter is written as three dots ââŚâ
- -
- Serialisation is the conversation of data saved in the memory on different adresses into a flat description. A use case is to store data and send it over to another computer.
- JSON is a popular serialisationformat.
- The object names are written in double quotes " ⌠".
-
strings and integers can only hold a single type of data.
-
an array can store multiple values.
-
properties are values.
-
null and undefined do not have properties
-
the 2 main ways are with a dot and square brackets.
-
methods are properties that contain functions of the value they belong to
-
objects are arbitrary collections of properties.
-
objects can store a list of activities and a boolean value
-
using braces as an expression
-
the values of objects can be changed
-
because they are not objects
-
a function that accepts any number of arguments
-
serialization is converting data into a flat description so that you can save the file for later or send it to another computer over the network
-
JSON is a serialization format which stands for Javascript Object Notation used as data storage and communication format on the web.
-
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.
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 chapter introduce the problem that string and integers cannot store more than one element. If we want to store list of numbers in one variable, it is not possible with integer. We need different kind of variable that able to store multiple elements in it.
What variable type can be used in order to solve the problem of storing multiple values?
To store multible values we can use array.
What are properties in Javascript?
Properties are values of the objects in JavaScript.
Which values do not have properties?
null and undefined.
How can we access properties in a value (two ways)?
using varible name and then dot and the property name > variable_name.property_name
using varible name and then square brackets > variable_name[property_name]
What are methods?
Properties that contain functions. Basically methods are functions that call the value of the property.
What are objects?
Objects are special variables that can store several different types of values in it. It is like collections of properties
What problem do objects solve that cannot be solved with other value types we've learned so far (such as integer, string, array, boolean etc)?
We cannot store different type of values in integer, string, array, boolean etc. With objects we can store all kind of type of values just in one variable.
How do you define an object?
Object is a bag of values, we can put every type of value in this bag, and we can use it anytime by calling it.
What can you say about the mutability of Javascript objects?
Mutability of JavaScript objects provide us flexibility. We can change, remove and add properties to objects easily.
Second part
Why can't you add new properties to a string variable?
String variable is not an object. There are some build-in properties for non-object variables in javascript and we cannot add more properties to non-obkect variables by default.
What are rest parameters?
Rest parameters is used for provide ability to put infinite numbers of arguments as an array to functions. Rest parameters can be used with triple-dot.
What is serialisation and what is a use case of serialisation of data?
Serialisation is converting the data structures or object into a format that can be stored easily. The use case of serialisation of data is storage of the data in datastore instead of computer memory. So that we do not need to transmit whole computer memory to transfer the data.
What is JSON?
JSON is a popular serialization format which 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?
In JSON all property names have to be surrounded by double quotes, in objects we do not have to use double quotes for property names.
In JSON, function calls, bindings or any computation is not allowed, while in objects it is allowed.
In JSON, comments are not allowed, while in objects it is allowed.
The WereSquirrel
- 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?
- His collection of numbers needs to be addressed as a single âthingâ.
- What variable type can be used in order to solve the problem of storing multiple values?
- An array
- What are properties in Javascript?
- Properties are a kind of built-in expression or function that can be applied to an array or a string, which is also a kind of array. Examples include .length, .max or .min. The latter two are functions of the Math object, a collection of mathematics-related constants and functions.
- Which values do not have properties?
-
null
andundefined
do not have properties.
- How can we access properties in a value (two ways)?
- with a dot
- value.x
- x is the literal name of the property
- eg. min or max or length
- value.length is easier to write than value[âlengthâ]
- x is the literal name of the property
- value.x
- with square brackets
- value[x]
- x is an expression that is evaluated and will be the name of the returned value
- eg. value[5-2] evaluates to value[3] and retrieves the 4th member of an array
- eg. value[âJohn Doeâ] retrieves a value named âJohn Doeâ
- x is an expression that is evaluated and will be the name of the returned value
- value[x]
- What are methods?
- Methods are properties that manipulate the data in some way, that is, properties that contain functions.
- value.toUpperCase is a âmethodâ of a string, which converts the string to upper case! eg. doh.toUpperCase
- What are objects?
- Objects are arbitrary collections of properties.
- What problem do objects solve that cannot be solved with other value types weâve learned so far (such as integer, string, array, boolean etc)?
- Arrays cannot include differing value types. With an object you can include some values of varying types.
- How do you define an object?
- Use braces as an expression. for example:
let day1 = {
squirrel: false,
events: ["work", "touched tree", "pizza", "running"]
};
- What can you say about the mutability of Javascript objects?
- Value (numbers, strings and Booleans) in JavaScript are immutable, once created their values cannot be changed. You can use those values or strings to make new values, but nothing can change the string containing âcatâ so that it spells âratâ.
- In contrast, consider these three objects, object2 is literally equal to object1, but object3 is only coincidentally equal to object1.
let object1 = {value: 10};
let object2 = object1;
let object3 = {value: 10};
console.log(object1 == object2); // â true
console.log(object1 == object3); // â false
object1.value = 15;
console.log(object2.value);
// â 15
console.log(object3.value);
// â 10
Objects are mutable. We can change the properties of an object.
Strings and their properties
- Why canât you add new properties to a string variable?
- Strings are immutable. You can try to add a new property to a string array, but nothing happens. It remains
undefined
.
- What are rest parameters?
- A rest parameter is where you put three dots
...
immediately before the last parameter in order to allow it to accept an unlimited number of parameters (the rest of the parameters).
For example,function max(...numbers) {
⌠- This binds the rest parameter to an array containing all further arguments.
- (Feel free to skip the sub-chapter of Math object and Destructing)
- with pleasure!
- What is serialisation and what is a use case of serialisation of data?
- The objects are actually references to the memory locations of the contents of the object! To send the object somewhere we need to flatten them into a list of the properties with their values.
- To share or analyse our data we may output it as JSON.
- This may be read by a webpage for display, or manipulated in order to fill a spreadsheet table.
- What is JSON?
- JSON is a popular format for serializing (and therefore describing) object data; JavaScript Object Notation.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
- JSONâs format is much like the JavaScript way of writing objects and arrays, but
- all property names need to be in double-quotes and
- you cannot include calls to functions or bindings.
- That is, you cannot actually compute with a JSON object.
- You also cannot put any comments into JSON.
fin
What problems does this chapter introduce that cannot be solved with variable types such as strings or integers? Working with data sets that are too large or complex to be solved with only string or integer variables
What variable type can be used in order to solve the problem of storing multiple values? An array
What are properties in Javascript? Properties are the values associated with an object
Which values do not have properties? Null and Undefined
How can we access properties in a value (two ways)? Using the format âobject.xâ or "object[x]"
What are methods? Properties that contain functions
What are objects? Objects are containers for named values called properties or methods.
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 make the storage and usage of larger more complicated data set easier
How do you define an object? Objects are containers for named values called properties or methods.
What can you say about the mutability of Javascript objects? It is possible to change object properties and therefore change their values; this is known as mutability
Why canât you add new properties to a string variable? String variables are not objects and are therefore immutable
What are rest parameters? The rest parameter that has a prefix of three dots (âŚ), and allows you to represent an indefinite number of arguments as an array.
What is serialisation and what is a use case of serialisation of data? Serialisation is the process of translating the structure and value of an object into a flat file that can then be stored for later use; i.e. transmitted across the internet
What is JSON? JavaScript object notation (JSON) is a format used in the serialization of data
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. Comments are not allowed in JSON.