This is the fourth blog in the series of twenty-one blogs that bring together my understanding from the book EloquentJS. The book at this point starts with a fictional story of a boy named Jaques, who turns into a squirrel on eating peanuts and not brushing his teeth. So to get to this result he applies all the concepts that are taught in this chapter.
Say, for example, that we want to represent a collection of the numbers 2, 3, 5, 7, and 11.
We could get creative with strings and we would have to somehow extract the digits and convert them back to numbers to access them....that is a lot of work.
NOTE- The first index of an array is zero, not one.
Expressions like myString.length and Math.max are those statements that access a property of some value.
Two main ways to access properties in Java Script are with a Dot and Square Brackets.
Properties that contain functions are generally called methods. Both string and array values contain, in addition to the length property, a number of properties that hold function values.
For example, toUpperCase and toLowerCase convert text to 'CAPITALS' and 'notcapitals'.
Values of the type object are arbitrary collections of properties. One way to create an object is by using braces as an expression.
Objects are usually represented by ---> Key:value or identity:property.
Delete option deletes an object. But, there is a difference between setting a property to undefined and actually deleting it is that, in the first case, the object still has the property (it just doesn’t have a very interesting value), whereas in the second case the property is no longer present and in will return false.
What properties does an object have? Object.keys
Copy all properties from one object to another? Object.assign
Object values can be modified. The types of values, such as numbers, strings, and Booleans, are all immutable—it is impossible to change the values of those types.
Objects work differently. You can change their properties, causing a single object value to have different content at different times.
The Lycanthrope's Log:
Correlation is a measure of dependence between statistical variables. A statistical variable is not quite the same as a programming variable. In statistics you typically have a set of measurements, and each variable is measured for every measurement.
To compute the measure of correlation between two Boolean variables, we can use the phi coefficient (ϕ).
Correlation between variables is usually expressed as a value that ranges from -1 to 1.
This works not only for arrays but also for strings and some other data structures.
Push & Pop ---> add and remove elements at end of the array
Shift & Unshift ---> add and remove elements at the start of the array
getTask() --->get front item from queue.
rememberUrgently ---> adds a task in front of the queue.
LastIndexOf ---> to search from the end instead of the start.
Slice ---> takes start and end indices and returns an array with elements in between.
conactenation ---> Refer to Blog1
Strings and Their Properties:
length ---> length of the string
slice, indexOf ---> string’s indexOf can search for a string containing more than one character, whereas the corresponding array method looks only for a single element.
Trim --->removes whitespace (spaces, newlines, tabs, and similar characters) from the start and end of a string.
Split and Join --->You can split a string on every occurrence of another string with split and join it again with join.
It can be useful for a function to accept any number of arguments.
To write such a function, you put three dots before the function’s last parameter.
such a function is called, 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.
You can use a similar three-dot notation to call a function with an array of arguments.
The Math Object:
Math.max (maximum), Math.min (minimum), and Math.sqrt (square root). cos(cosine), sin(sine), tan(tangent) supports their inverse as well as acos, asin and atan. Also supports the number pi to the closest approximation.
Math.random --->This is a function that returns a new pseudorandom number between zero (inclusive) and one (exclusive) every time you call it.
There are also the functions Math.ceil (for “ceiling”, which rounds up to a whole number), Math.round (to the nearest whole number), and Math.abs, which takes the absolute value of a number, meaning it negates negative values but leaves positive ones as they are.
NOTE: Having too many global bindings “pollutes” the namespace.
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. A popular serialization format is called JSON.
Comments are not allowed in JSON.