-
You can actually set up a property to a string variable BUT it doesn’t store those properties. This is because strings, numbers and Booleans are not objects and are Immutable (cannot be changed)
-
These are parameters that accepts any number of arguments, written by placing three dots before the function’s last parameter.
-
Serialisation or serialize the data means that the memory of the addresses of the values are converted into a flat description
-
JSON stands for JavaScript Object Notation which is a popularized serialization format that is widely used as a data storage and communication format on the Web
-
The differences between JSON and writing objects in plain JS is that all property names have to be surrounded by double-quotes. It allows simple data expressions only (i.e. no function calls, bindings, or anything that involves computation, and no comments are allowed.
-
New problem: Information needs to be grouped and categorized using arrays and objects.
-
An arrays primary function is storing multiple values.
-
Expressions that access a “property” of value.
-
Null and Undefined.
-
with a dot “.” or with square brackets “[]”.
-
A property that holds function value.
-
Data structures that are capable of containing an arbitrary collection of properties using parameter braces.
-
Objects allow you to further categorize multiple pieces of necessary data inside the block.
-
By using braces to define the parameters in relation to the variable.
-
Allows you to efficiently categorize necessary data, providing transparency and flexibility to your code.
-
A string does not function like an object as their parameters are already defined with built in properties.
-
3 dots added to the beginning of the functions last parameter. This allows functions to permit any number of arguments.
-
N/A
-
The process of converting data structures or an object state into a format that can be stored. Used to save data then send to another computer in the network.
-
Java Script Object Notation, also an example of serialization.
-
Simplified expressions are only allowed in JSON, no function calls, bindings, or applicable computation.
Part 1
- Creating an Array solves the problem of having to use multiple variables.
- An Array is an example of storing multiple values.
- Properties are values inside an object.
- NULL & UNDEFINED
- for example: length could be requested by typing // array.length OR array[“length”] - its important to note that the “DOT” Version is not always available. For numbers & strings you always have to use [“string”].
- Methods are properties containing a function from the get go. Such as .push,.pop for adding or removing the last entry of an array or examples like .toUpperCase for letting the string be ALLCAP. .toLowerCase obv. is for nocap.
- Objects are collections of properties. For example storing a boolean with an array. could look like this: { string: true, array[1,2,3,4]};
- Objects can combine value types whereas strings, etc. only store one.
- defining an object: let object { value 1, value 2}; like // let squirrel{string:true, array[1,2,3,4]};
- different objects could have the same value without living in the same world.
OBJ1 = 10; OBJ2 = OBJ1; OBJ3 = 10 - If you change OBJ1 to 15 ; OBJ2 will follow whereas OBJ3 still stays with its value of 10.
Part 2
- You cant add properties to primitive datatypes as they are not treated as objects.
- its a function with multiple arguments displayed with three dots. Like so max(…numbers);
- READ
- Its a way of converting data in bits to send / receive data easily to/from different networks.
- short for JavaScript Object Notation - making transfer of information between networks easy.
- JSON is used for simple data, no functions or computations possible. It has all properties surrounded by " " .
- 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 needs to be solved using groups of values eg each day and what happened during the day, if he was a weresquirrel or not.
- What variable type can be used in order to solve the problem of storing multiple values?
An array allows us to store multiple values as a variable
- What are properties in Javascript?
Properties are in different value types and objects. Elements in an array are stored as the array’s properties. An array is an object. It holds different values and properties. You can have an array of objects (see page 65 in Eloquent Javascript book).
- Which values do not have properties?
Null & undefined.
- How can we access properties in a value (two ways)?
You can do value.x or value[x], for example someString.length, or array[“length”]
- What are methods?
A method is a property that contains functions. Methods of the value they belong to, such as toUpperCase is a method of a string. Push and pop methods add or remove values in an array.
- What are objects?
Objects are a way to group values, properties and other objects together.
- 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 allows us the group values together into a single value.
- How do you define an object?
An object is defined by using braces as an expression and listing the properties separated by commas. Properties that don’t have valid binding names or numbers need to be quoted. A property is named, then separate the value after it with a colon.
- What can you say about the mutability of Javascript objects?
Objects are mutable, you can change their properties.
- Why can’t you add new properties to a string variable?
String variables are immutable, they cannot be changed.
- What are rest parameters?
Rest parameters are used by putting 3 dots before the functions last parameter.
This will add the elements to the arguments list.
Example let fruit = [“apple”, “orange”];
console.log([“pear”, …fruit]);
// [“pear”, “apple”, “orange”]
- What is serialisation and what is a use case of serialisation of data?
Serialisation of data means to convert data into a flat description like JSON. It is much smaller in size and can be more easily sent on the web.
- What is JSON?
JavaScript Object Notation, it is used to send data across the web, it is also used in languages other than javascript. Only simple data expressions are allowed (no function calls, bindings, computation or comments). It is written with all property names surrounded by double quotes.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
The property names have to be in double quotes. Can’t use bindings or function calls.
Chapter 4 Data Structures: Objects and Arrays
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?
Multiple types of data are needed to be recorded in order to unravel his squirrel problem. Strings and integers are only designed to hold a single type of data, therefor making them non-efficient in this problem.
- What variable type can be used in order to solve the problem of storing multiple values?
An array
- What are properties in Javascript?
It is an characteristic of an object, in most cases describing attributes associated with a data structure. There are instance properties which hold data that are specific to a given object instance. There are static properties which share data among all object instances.
- Which values do not have properties?
Undefined and null don’t have properties.
- How can we access properties in a value (two ways)?
Properties can be accessed using the dot property: (object.property)
Properties can also be accessed using square brackets: object[property]
- What are methods?
Actions that can be performed on objects. A javascript method is a property containing a function definition. Methods are functions stored as object properties.
- What are objects?
An object is a collection of properties, and is one of JavaScripts data 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 many different data types as opposed to just ‘1’ in a string for example.
- How do you define an object?
Objects are containers for named values called properties or methods. They can be defined as any other variable within braces.
- What can you say about the mutability of Javascript objects?
There is no binding between objects unless it is specifically written in the code to do so. Otherwise they share no deep comparison.
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?
Strings are not objects, and they won’t store new properties set on them. They are referred to as immutable.
- What are rest parameters?
They allow a function to accept an indefinite amount of arguments as an array. This is performed by … before the last parameter.
- (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?
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() . If you want to keep the actual data generated from the code run on one computer and send to another computer on the same network you can use JSON.
- What is JSON?
A format for storing and transporting data from one computer to the next.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON only allow simple values expressions like strings, numbers, arrays and booleans. Objects require multiple properties and data types.
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?
With strings, you would have to somehow extract the digits and convert them back to numbers to access them. This would be difficult and require a lot more coding than necessary, in comparison to using arrays.
2. What variable type can be used in order to solve the problem of storing multiple values?
Arrays are variables that let you store lists of values.
3. What are properties in Javascript?
Properties are values / characteristics of an object. They describe attributes that are associated with a structure of data. A few examples are Maximum, minimum, and Length.
4. Which values do not have properties?
The null and undefined values do not have properties and return an error.
5. How can we access properties in a value (two ways)?
The two ways to access properties are to use a dot and to use square brackets. For example .x and [x] The dot way can be used for valid binding names such as .length, and the bracket way is used when property names such as [“Example”]
6. What are methods?
Methods are properties that contain functions yet do not pass any arguments. Examples of methods include “toUpperCase’ and ‘toLowerCase’ Also there are methods that can be used to manipulate arrays such as .push to add values and .pop to remove values.
1. What are objects?
Objects are variables that store collections of properties, values, and methods.
2. 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)?
Values can be modified, unlike strings, integers, arrays, and booleans which cannot be modified. They are immutable, whereas objects are mutable.
3. How do you define an object?
Objects are defined by using braces to create an expression. Inside the braces, you can create a list of properties separated by commas. For each property, you create a name followed by a colon and then a corresponding value. If a property’s name is not a valid binding or number then you will add quotations around it.
4. What can you say about the mutability of Javascript objects?
Objects can have their properties changed which can cause a single object value to have different content at different times.
Subchapter - Strings and their properties
1. Why can’t you add new properties to a string variable?
Because strings are immutable and cannot be changed.
2. What are rest parameters?
The last parameter in a function. This is created after three dots that allow the function to accept an indefinite number of arguments in an array.
3. What is serialisation and what is a use case of serialisation of data?
Serialization means to convert the data into a flat description, this is used to store and transfer data more effectively.
4. What is JSON?
JSON stands for JavaScript Object Notation and is a serialization format. It is used as a data storage and communication format for the Web.
5. 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 data is expressed in simpler terms. Jason does not include function calls bindings or things that involve computation, and also comments are not accepted.
-
Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Data structures that include a variety of data types (strings, boolean, and/or numbers in one group of a particular data structure) -
What variable type can be used in order to solve the problem of storing multiple values?
object -
What are properties in Javascript?
Properties are characteristics of values in a data structure -
Which values do not have properties?
Null and undefined -
How can we access properties in a value (two ways)?
value.property or value[“property”] -
What are methods?
properties that contain functions -
What are objects?
Values of type object 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)?
When you want to include pieces of different data types in one data structure -
How do you define an object?
Objects can store different kinds of values in one values by using braces and Inside the braces, there is a list of properties separated by commas. Each property has a name followed by a colon and a value. -
What can you say about the mutability of Javascript objects?
object values can be modified. The types of values such as numbers, strings, and Booleans, are all immutable.it is impossible to change values of those types. Objects work differently. You can change their properties, causing a single object value to have different content at different times.
SECOND PART:
-
Why can’t you add new properties to a string variable?
Because strings are not objects, they only have build in properties -
What are rest parameters?
When there are an unknown number of parameters in a function this notation allows us to write and call functions with an unspecified number of 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?
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 is JSON?
Javascript Object Notation - a data serialization syntax -
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.
- 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?
Some problems require arrays to solve. This happens when you need to store a sequence of values for later use.
- What variable type can be used in order to solve the problem of storing multiple values?
Array variable type
- What are properties in Javascript?
Properties are descriptions of a given value that can be returned with a function.
- Which values do not have properties?
Null and undefined.
- 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?
Methods are properties that contain functions.
- What are objects?
A value that is an arbitrary collection of properties.
- What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
Objects can continue to store additional data in them over time.
- How do you define an object?
An object is something that can have properties and functions just like anything else I would consider to be an object outside of JavaScript. For example, my computer (object) is a desktop (property) and I have two monitors (property). It can mine cryptos (function) and allow me to take online courses (function).
- What can you say about the mutability of Javascript objects?
An object can have a stack of values. You can add values and remove them too. In this since, the object is mutable where as a string, Boolean, or number value is not.
Strings and their properties.
- Why can’t you add new properties to a string variable?
Strings are immutable in what properties they have, although strings still do come with a set of properties.
- What are rest parameters?
A function can accept any number of arguments by using 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 serialisation and what is a use case of serialisation of data?
Serialisation is when array data is converted into a flat description and is used to transfer array data across a network.
- What is JSON?
JavaScript Object Notation
- What are the differences between JSON and the way programmers write objects in plain Javascript?
JSON requires 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.
-
that we need to store values for later use
-
arrays
-
properties are “descriptions” of an object.
-
null and undefined.
-
with a Dot or with square brackets.
-
properties that contain functions.
-
are arbitrary collections of properties
-
mutability
-
an object in Js would be much like an item on a game, it can have functions and/or properties
-
values in number, strings and booleans are immutable, where in objects they are mutable
-
because strings are immutable
-
a function that accepts any number of arguments,
-
- (Feel free to skip the sub-chapter of Math object and Destructing) -
-
is when the data is converted into a “flat description” popularly used: JSON
-
JavaScript Object Notation
-
All property names must be surrounded by double quotes, and only simple data expressions. theres no functions, bindings or anything that involves actual computation or comments.
FIRST PART:
-
If Jacques used normal strings or integers to keep a daily of everything he does on a given day whether he changed form (true or false), first he will have to create (define) new variable everyday, second he will have hard time managing the data.
-
Array
-
Properties are the features or the characteristics that values or data have. For example, var data = [1,2,3] has length 3.
-
null and undefined. Null is like empty set (∅) from mathematics.
-
The two ways to access properties are with a dot and with square brackets. When using dot, you write the literal name of the property while with square brackets, you write property name. For example,
objectName.property
orobjectName["property"]
. -
Methods are properties that contains functions. Array.length just tell the length of the array and doesn’t change the array at all, however Array.push(5) pushes 5 to the array which changes the property of the array.
-
Objects are arbitrary collections of properties.
-
Integers and strings are limited to one value. Arrays are limited in storing sequences of values, and each elements are assigned by number. Objects are more open, you can assign properties by yourselves.
-
By using curly braces. For example,
let Ivan = { nationality : "Sweden", job: "YouTuber", age: 25, cryptoInvestor: true};
-
Objects are mutable, you cannot change their properties.
SECOND PART:
-
String variables are intended to only store strings. And this cannot be changed.
-
Rest parameters syntax accept any number of arguments. To use this, you put three dots before the functions’s LAST parameter.
-
-
Serialization means converting objects into a flat description. It is used when transmitting object data to another computer.
-
JSON (JavaScript Object Notation) is a popular serialization format. It is widely used as data storage and communication format on the Web. Application’s settings such as Vscode are saved in JSON format.
-
In JSON format, all property names have to be surrounded by double quotes and only simple data expressions are allowed (no function calls, bindings, or computation).
Q: In the textbook it says, comments are bot allowed, however I do put comments in VsCode’s setting.json, but I have no issue. Why is that?
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?
It introduces a problem that can be solved using a data structure that stores multiple values.
2). What variable type can be used in order to solve the problem of storing multiple values?
Arrays and Objects
3). What are properties in Javascript?
A characteristic of of an object, often describing attributes associated with a data structure.
4). Which values do not have properties?
Null and undefined
5). How can we access properties in a value (two ways)?
(i) Using a dot e.g array.length
(ii) Using square brackets e.g value [i]
6). 1. What are methods?
Methods: properties that contain functions are generally called methods of the value they belong to.
7). What are objects?
An abstract data type with values that are 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)?
Problems where a data type has to hold variables of more than one data type.
9). How do you define an object
Objects are defined using braces as an expression. Inside the braces, there’s a list of properties separated by commas. Each property has a name followed by colon and a value.
10). What can you say about the mutability of Javascript objects
It means that JavaScript objects value can be changed.
SECOND PART
1). Why can’t you add new properties to a string variable?
Because string variables are immutable.
2). What are rest parameters: The rest parameters syntax allows a function to accept an indefinite number of arguments.
3). (Feel free to skip the sub-chapter of Math object and Destructing)
skipped
4). What is serialisation and what is a use case of serialisation of data?
Serialization is the conversion of data into a flat description. It is widely used as a data storage and communication format on the web.
5).What is JSON? Is a popular serialization format which stands for JavaScript Object Notation.
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 - n function calls, no bindings or anything that involves actual computation and comments are not allowed in JSON
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?
Each entry needs to store a list of activities and a Boolean value that indicates whether Jacques turned into a squirrel or not. Then group them together into a single value and then put into an array of log entries.
2. What variable type can be used in order to solve the problem of storing multiple values?
Objects
3. What are properties in Javascript?
A Value that is possibly held by object
4. Which values do not have properties?
Null and undefined
5. How can we access properties in a value (two ways)?
. And []
6. What are methods?
Properties that contain functions
7. What are objects?
Values of that contain 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)?
They are mutable
9. How do you define an object?
One way is by using braces as an expression
10. What can you say about the mutability of Javascript objects?
You can use “let” binding to keep track of a changing number by changing the value the binding points at. “const” bindings can not be changed and will continue to point at the same object, though the contents of that object might change.
1. Why can’t you add new properties to a string variable?
They wont be stored, the values are immutable they cant be changed
2. What are rest parameters?
It binds to an array containing all arguments in the parameter.
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 means data is converted into a flat description like JSON so you don’t have to send over your entire computer memory along with the addresses of the value you are interested in.
5. What is JSON?
JavaScript Object Notation, is a widely used serialization format.
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 computation, or comments.
-
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 integers are not values that can be changed. In our squirrel problem, we need multiple values that can be changed in order to calculate our more complex data over a period of time. -
What variable type can be used in order to solve the problem of storing multiple values?
Arrays can be used to solve the problem of storing multiple values. -
What are properties in Javascript?
Properties are characteristics of values within an object. -
Which values do not have properties?
Null and Undefined -
How can we access properties in a value (two ways)?
You can access properties by either using value.x or value[x] When using the brackets, the expression between the brackets is evaluated to get the property name. -
What are methods?
Methods are properties that contain functions for a value. -
What are objects?
Objects are variables that contain many values that are written in name:value pairs. -
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 help to solve complex problems with the use of multiple values or properties that can be changed to fit the data. -
How do you define an object?
An object is defined with a name, curly brackets, and value pairs that are separated with commas. -
What can you say about the mutability of Javascript objects?
Mutability means the content of a value can be modified by changing it’s properties.
SECOND PART:
-
Why can’t you add new properties to a string variable?
String variables are primitave and therefore immutable. -
What are rest parameters?
Rest Parameters allow us to represent any number of arguments as an array. -
(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?
Serialization is when the data is converted into a flat description for use as data storage and for sending data over the internet -
What is JSON?
JSON stands for Java Script Object Notation and is a format for storing and transporting data. -
What are the differences between JSON and the way programmers write objects in plain Javascript?
Only simple data expressions(no computations) are allowed and all property names must be surrounded by double quotes.
-
Sorting, and storing data in an organised way
-
Arrays
-
Math.max, Max.min
A property is an attribute associated with a data structure. It has a string, and a value.
-
Null and undefined
-
First way is with a dot .
Second way, with square brackets [ ]
-
Methods is a property containing a function.
-
Loose data that you group together, and create data structures
-
Objects let us group together data that suits your needs
-
Use curly braces { }
Object = { }
- Objects in javascript can have different values, and can be changed, therefore they are mutable
1. Strings are immutable
2. Allows a function to accept an indefinite number or arguments.
3. Skipping
4. Morphing data or an object into a format so that can be stored
5. JavaScript Object notation, data storage a comms for the internet
6 Properties should be written in double quotes, you cannot make comments in JSON
So there may be some ones that I missed the mark on understanding on, just let me know
-
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. He needs a data structure that stores multiple values. -
What variable type can be used in order to solve the problem of storing multiple values?
A. Arrays and objects -
What are properties in Javascript?
A. Access property of some value like Math.max. -
Which values do not have properties?
A. The exceptions are null and
undefined -
How can we access properties in a value (two ways)?
A. The two main ways to access properties in JavaScript are with a dot and with
square brackets. Both value.x and value[x] access a property on value—but
not necessarily the same property. -
What are methods?
A. Properties that contain functions are generally called methods -
What are objects?
A. Values of the type object 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)?
A. Objects hold together in a single value many datatypes. -
How do you define an object?
A. Values of the type object are arbitrary collections of properties. One way to
create an object is by using braces as an expression. -
What can you say about the mutability of Javascript objects?
A. The types of values as numbers, strings, and Booleans, are all immutable—it
is impossible to change values of those types. You can combine them and derive
new values from them, but when you take a specific string value, that value
will always remain the same. The text inside it cannot be changed -
Why can’t you add new properties to a string variable?
A. As they are immutable and cannot be changed. -
What are rest parameters?
A. the rest parameter is bound to an array
containing all further arguments. If there are other parameters before it, their
values aren’t part of that array. -
(Feel free to skip the sub-chapter of Math object and Destructing)
A. Done. -
What is serialisation and what is a use case of serialisation of data?
A. , objects and
arrays are stored in the computer’s memory as sequences of bits holding the
addresses—the place in memory—of their contents. These objects are serialized to convert the data to a flat description. -
What is JSON?
A. A popular serialization format is called JSON (pronounced
“Jason”), which stands for JavaScript Object Notation -
What are the differences between JSON and the way programmers write objects in plain Javascript?
A. 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. 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?
This chapter introduces data structures allowing for the ability to store information as multiple chunks of data.
2. What variable type can be used in order to solve the problem of storing multiple values?
Arrays, which is a type of object used for storing multiple values in a single variable. Each value (also called an element) in an array has a numeric position, known as its index, and it may contain data of any data type-numbers, strings, booleans, functions, objects, and even other arrays.
3. What are properties in Javascript?
Expressions that access a property of some value.
var array = [1, 2, 3, 4, 5]
array.length
// 5
4. Which values do not have properties?
null has no properties
undefined has no properties
If you try to access a property on one of these nonvalues you will get an error.
5. How can we access properties in a value (two ways)?
The two main ways to access properties in Javascript are with a dot, in which the word after the dot is the literal name of the property and with square brackets, in which the expression between the brackets is evaluated to get the property name.
var myArray = [5, 4, 3, 2, 1]
myArray.length
// 5
var arrTwo = ["John", "Bob", "Alice", "Mike"]
arrTwo.length
// 4
arrTwo[1]
// "Bob"
arrTwo[2 -1]
// "Bob"
arrTwo.push("Alex")
// ["John", "Bob", "Alice", "Mike", "Alex"]
arrTwo.pop()
// "Alex"
// ["John", "Bob", "Alice", "Mike"]
arrTwo.shift()
// "John"
// ["Bob", "Alice", "Mike"]
6. What are methods?
A JavaScript method is a property containing a function definition.
Properties that contain functions are generally called methods of the value they belong to. Methods are actions that can be performed on objects.
ie:
var name = "vichy catalan"
name.toUpperCase()
// "VICHY CATALAN"
var num = "12"
parseInt(num)
// 12
var num = 12
num.toString()
// "12"
Math.floor(Math.random() * 10)
// Generates a random number from 0-9
var person = {
firstName: "Vichy",
lastName : "Catalan",
fullName : function() {
return this.firstName + " " + this.lastName;
}
}
console.log(person.fullName().toUpperCase())
// VICHY CATALAN
7. What are objects?
Values of type object are arbitrary collections of properties. One way to create an object is by using braces as an expression and then listing your data as key/value pairs separated by commas, leaving out the last trailing comma. Properties whose names aren’t valid binding names or valid numbers have to be quoted.
var stock = {
Company: "Netflix Inc",
Price: 540.97,
Name: "NFLX"
}
for(let [key, value] of Object.entries(stock)){
console.log(`${key}: ${value}`)
}
/*
Company: Netflix Inc
Price: 540.67
Name: NFLX
*/
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, including other objects, to build more complex structures and are also mutable, unlike number, string, and boolean types. Object properties can be changed, causing a single object value to have different content at different times.
9. How do you define an object?
Objects are variables too. But objects can contain many values. The values are written as name:value pairs (name and value separated by a colon). JavaScript objects are containers for named values called properties or methods.
You define (and create) a JavaScript object with an object literal.
The name:values pairs in JavaScript objects are called properties:
var person = {
firstName: "Marijn",
lastName: "Haverbeke",
age: 50,
eyeColor: "brown"
};
10. What can you say about the mutability of Javascript objects?
Mutable is a type of variable that can be changed. 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?
Javascript Strings are immutable, which means once a String object is assigned to String reference the object value cannot be changed. The method will return a new String object it will not change the existing String reference. So we have to assign it to a new variable to get the desired value.
2. What are rest parameters?
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic functions in JavaScript.
When a function is called, the rest parameter is bound to an array
containing all further arguments.
var x = ["a", "b", "c"]
var y = ["d", "e", "f"]
var z = [ ...x, ...y, "h", "i", "j"]
// ["a", "b", "c", "d", "e", "f", "h", "i", "j"]
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?
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. Javascript gives us the functions JSON.stringify() and JSON.parse() to convert data to and from this format, converting it into a flat description.
5. What is JSON?
Javascript Object Notation:
JSON is a syntax for storing and exchanging data. JSON is text, written with JavaScript object notation. When exchanging data between a browser and a server, the data can only be text.
JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server. We can also convert any JSON received from the server into JavaScript objects.
This way we can work with the data as JavaScript objects, with no complicated parsing and translations.
// JSON data entered in Postman:
var myObj = {
"amount": "100",
"sender": "0000HFH9796F99TATFFS243",
"recipient": "00007HO08YYGHY8T9O9NHP"
}
JSON.stringify(myObj)
// "{"amount":"100","sender":"0000HFH9796F99TATFFS243","recipient":"00007HO08YYGHY8T9O9NHP"}"
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
The JSON syntax is a subset of the JavaScript syntax. A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value.
JSON syntax is derived from JavaScript object notation syntax:
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
JSON names require double quotes. JavaScript names don’t.
In JSON, keys must be strings, written with double quotes.
In JSON, values must be one of the following data types:
- a string
- a number
- an object (JSON object)
- an array
- a boolean
- null
In JavaScript values can be all of the above, plus any other valid JavaScript expression, including:
- a function
- a date
- undefined
Object Syntax:
- JSON objects are surrounded by curly braces {}.
- JSON objects are written in key/value pairs.
- Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null).
- Keys and values are separated by a colon.
- Each key/value pair is separated by a comma.
Arrays:
- Arrays in JSON are almost the same as arrays in JavaScript.
- In JSON, array values must be of type string, number, object, array, boolean or null .
- In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
- Arrays can be values of an object property
- Values in an array can also be another array, or even another JSON object
-
Strings and integers cannot store multiple values or lists of data sets.
-
An Array can hold lists of data.
-
Properties in JavaScript are used to define characteristic elements in a dataset, such as length or color.
-
The values null and undefined do not have properties.
-
The two main ways to access properties in JavaScript are with a dot and with
square brackets. -
Methods are properties that contain functions and only work on the value in which they belong.
-
Objects are values that can be used as a group of properties.
-
Objects can hold values of different types and have the ability to change and manipulate the values.
-
An object is defined by square brackets.
-
Objects can be changed and manipulated, therefore they have mutability.
Next section:
-
A string is not an object and therefore immutable.
-
Rest parameters passes elements of an array as separate parameters.
-
Serialization is converting data into a “flat” description that can be sent to storage or over the network for use.
-
JSON (JavaScript Object Notation) is a serialization format widely used for
data storage and communication on the Web. -
In JSON, all property names have to be surrounded by double quotes, and only simple data expressions are allowed. This means that no function calls, bindings, comments or anything that involves actual computation.
PART 1:
-
Arrays are a more organized way to represent digital data, and helps avoiding the double job of extracting the digits and convert them back to numbers.
-
Arrays and in a slightly more complex way, Objects too.
-
With the exception of null and undefined, all JS values have properties. They are a characteristic of an Object, often describing attributes associated with a data structure. An Object it’s a collection of properties, and a property it’s an association between a name and a value.
-
Null and undefined
-
With a dot or square brackets
-
Methods are actions that can be performed on Objects. A JS method it’s a property containing a function definition. Methods are functions stored as Object property.
-
An object it’s a collection of properties. Values are written as name:value pair, then colon, inside curly brackets.
-
Objects can solve problems regarding space, clarity and functionality, making very complex properties and collecting them in a clear and neat way, easy to read and recognise.
-
Objects are defined their property of being mutable, unlike booleans, strings, numbers etc… It has a name:value, colon, inside curly brackets.
-
JS Objects are mutable. Booleans, strings, numbers are instead immutable. Their property can be changed, causing a single object value to have different content at different time.
PART 2:
-
Because unlike Objects, these are immutable and can’t be altered.
-
Rest parameters are bound to an array containing all further arguments. Their values won’t be part of the array, if other parameters are before it.
-
-
It is the process whereby an object or data structure is translated into a format suitable for transferral over a network or a storage. In JS it is possible to serialise an object to a JSON string by calling the function JSON.
-
JSON(JavaScript Object Notation), is used widely as a data storage and communication format on the web, even in languages other that JS.
-
It is very similar , but all property names have to be surrounded by double quotes " ", and only simple data expressions are allowed. Comments, function calls, bindings or anything that involves actual computations are allowed.
First Part
Q: 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: They only can one information at a time. He needs a data structure to store all of the data in an organized way.
Q: What variable type can be used in order to solve the problem of storing multiple values?
A: An array can be used to store multiple data in a variable. It uses square brackets [] to store the multiple data collection. It also has a zero-based counting that starts from 0 and not 1 in this case.
Q: What are properties in Javascript?
A: Expressions like .length and .max can access properties of some value. If we write .length we can access the length property of the value in a variable.
Q: Which values do not have properties?
A: The only values that do not have properties are null and undefined values.
Q: How can we access properties in a value (two ways)?
A: With a dot (value.x) and with the square brackets (value[x]).
Q: What are methods?
A: Methods are properties that have function values. These functions work only on the value they belong to.
Q: What are objects?
A: Collections of properties.
Q: 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)?
A: Objects can contain inside of them a lot of values like integers, strings, arrays and Booleans, etc.
Q: How do you define an object?
A: You can create them by using braces. Ex: var a = {
tired: false,
routine: [“workout”, “shower”, “walk”, “study”]
};
Q: What can you say about the mutability of Javascript objects?
A: Objects unlike the other values that are immutable, can be modified. They can have their properties changed so that a single value can have different content at different times.
Second Part
Q: Why can’t you add new properties to a string variable?
A: Because the JavaScript language does not give this ability to strings because they are not objects and they are not allowed to contain additional properties.
Q: What are rest parameters?
A: They accept any number of arguments. We can use rest parameters by three dots. Ex: function max(…number)
Q: What is serialisation and what is a use case of serialisation of data?
A: Converting of data into a flat description format. We use it to send data to other computers or store it for later.
Q: What is JSON?
A: JSON is a serialization format that is very popular.
Q: What are the differences between JSON and the way programmers write objects in plain Javascript?
A: The simple expressions are allowed with quotations and comments are not allowed on JSON formatting.
- Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Data structure of many values - What variable type can be used in order to solve the problem of storing multiple values?
Arrays - What are properties in Javascript?
They are addtional values of variable like .max - Which values do not have properties?
null and undefined - How can we access properties in a value (two ways)?
wit dot or square brackets - What are methods?
Properties that contain functions are generally called methods of the value they belong to - 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)?
Objects can hold together many datatypes in a single value - How do you define an object?
collection of properties - What can you say about the mutability of Javascript objects?
numbers, strings, and Booleans, are allimmutable and objects are. You can change their properties
Part2
- Why can’t you add new properties to a string variable?
they are immutable - What are rest parameters?
Rest Parameters show any number of arguments as an array -
- What is serialisation and what is a use case of serialisation of data?
When we convert data into flat description - What is JSON?
A Serialisation format - What are the differences between JSON and the way programmers write objects in plain Javascript?
Just simple data expressions are allowed and all property names must be surrounded by double quotes. Comments are not allowed in JSON