Chapter 1: Values, Types and Operators

mysoresrividya

Srividya Mysore Venkatesh

Posted on December 3, 2020

Chapter 1: Values, Types and Operators

This is the first part of the twenty-one part series of blogs.I will be blogging my learnings from each chapter of the book EloquentJS."Below the surface of the machine, the program moves. Without effort, it expands and contracts. In great harmony, electrons scatter and regroup. The forms on the monitor are but ripples on the water. The essence stays invisibly below."...The book starts off with this quote. I personally think it kind of adds the importance of the work of a coder or a developer.

Bits:
Bits are any kind of two-valued things, usually described as zeros and ones. So they could be expressed as typically any opposites. Black and White, strong and weak electrical signal anything.

Values:
Imagine a sea of bits—an ocean of them. A typical modern computer has more than 30 billion bits in its volatile data storage and Nonvolatile storage (the hard disk or equivalent) tends to have yet a few orders of magnitude more. To be able to work with sooooo many bits we need better representation using chunks called 'values'.

Numbers:
Values of the number type are, unsurprisingly, numeric values.(HaHa). JavaScript uses a fixed number of bits, 64 of them, to store a single number value.

How to depict Fractional Numbers? Use a dot (like 8.34).
Big or small numbers use e(exponent)...like 7.994e4.
Calculation with Whole numbers is always precise. And with fractional numbers not quite hence use approximations.

Arithmetic:
Consider 13 + 11 * 9
The + and * symbols are called operators. Basically two values get along perform an operation and give out a new value( I mean that almost sounds like a relationship).
They are applied left to right. When in doubt, just add parentheses(sure. haha).
NEW OPERATOR IN TOWN!! The % symbol is used to represent the remainder operation. The remainder operator’s precedence is the same as that of multiplication and division. You’ll also often see this operator referred to as modulo.

Special Numbers:
The special entries here are Infinity, -Infinity, and NaN(Not a Number). These numbers are used to perform mathematical sins like infinity - 1, 0/0, Infinity - Infinity.

Strings:
A string is declared itself if it is enclosed within quotes. You can use single quotes, double quotes, or backticks to mark strings, as long as the quotes at the start and the end of the string match.
When does it get difficult? imagine how putting quotes between quotes might be hard
ROLE OF \n.... I am doing the neogcamp \n I aspire to be a Web Dev.
It Will is written as: I am doing the neogcamp.
I aspire to be a Web Dev.
Strings, too, have to be modeled as a series of bits to be able to exist inside the computer. The way JavaScript does this is based on the Unicode standard.
BTW, you cannot perform operations on strings. you can concatenate it but not add

"con"+"cat"+"e"+"nate"="concatenate"

Unary Operators
Not all operators are symbols.
typeof operator, which produces a string value naming the type of the value you give it.
Operators that use two values are called binary operators, while those that take one are called unary operators.
FUN FACT: The minus operator can be used both as a binary operator and as a unary operator.

Boolean Values
Distinguishes between only two possibilities, like “yes” and “no” or “on” and “off”.For this purpose, JavaScript has a Boolean type, which has just two values, true and false, which are written as those words.

Comparison
Compare two values using Comparison Operators.
Strings can be compared too!.
console.log("Aardvark" < "Zoroaster")
// → true
uppercase letters are always “less” than lowercase ones, so "Z" < "a".Goes from left to right, comparing the Unicode codes one by one.

FUN FACT: There is only one value in JavaScript that is not equal to itself, and that is NaN (“not a number”).

Logical Operators
There are also some operations that can be applied to Boolean values themselves. JavaScript supports three logical operators: and, or, and not.

&& AND operator results truly only if both values to it are true.
|| OR operator results true only if either value to it is true.

Ternary Operators
Operates on three values. When it is true, it chooses the middle value, and when it is false, it chooses the value on the right.
console.log(true ? 1 : 2);
// → 1
console.log(false ? 1 : 2);
// → 2

Empty Values
There are of these null and undefined, used to indicate absence of a meaningful value.

FUN FACT: The difference in meaning between undefined and null is an accident of JavaScript’s design!!

Automatic Type Conversion:

console.log("five" * 2)
// → NaN
console.log(false == 0)
// → true

When an operator is applied to the “wrong” type of value, JavaScript will quietly convert that value to the type it needs, using a set of rules that often aren’t what you want or expect. This is called type coercion.

Happy Reading!
SriV

💖 💪 🙅 🚩
mysoresrividya
Srividya Mysore Venkatesh

Posted on December 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Javascript : Program structure
teamtanayejschallenge Javascript : Program structure

December 5, 2020

Introduction to Javascript
teamtanayejschallenge Introduction to Javascript

December 5, 2020

Programme Structure
javascript Programme Structure

December 4, 2020

Reviewing Eloquent Javascript #Chpt5
javascript Reviewing Eloquent Javascript #Chpt5

December 11, 2020