# PREVIOUS: DAY 23

order 8: the fundamentals of Javascrpit (Technical aspect, Computer Science, Phase 1: a normal technican)

There are two types of number in Javascript, and they are stored as different data types. The first is regular numbers we're using, which are stored in 64-bit format. And the other is Bigint numbers, they are needed when we want to represent numbers more than 2^53 or less than -2^53.

A regular number is represented in the 64-bit format. Theoretically, it is able to store numbers between 2^64 to -2^64, for the computer is only able to recognize 0 and 1, and one digit requires one bit to store. However, among the whole 64-bit, 52 of them are used to store the digits, 11 of them store the position of the decimal point (they are zero for integer numbers), and 1 bit is for the sign. Hence, the regulat number is merely able to represent the number between 2⁵³ to -2⁵³.

1. style 1: let number = 7300000000
2. style 2: let number = 7_300_000_000 //The JavaScript engine ignores _ between digits
3. style 3:

(1) let number = 7.3e9 // 7.3bn, `e` multiplies the number by `1` with the given zeroes count

(2) let number = 1e-6 // one millionth, a division by 1 with the given number of zeroes

Aside from decimal number ,which is widely used for human, there are three numeral system that I have to know. The concept should be known while dealing with the computer.

1. Hex: Also called hexidecimal numbers. Their composition of numbers are 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. When encountering 16 in decimal number, it will hit the ceiling and become 10
2. binary: Their composition of numbers are 0 and 1. When encountering 2 in decimal number, it will hit the ceiling and become 10.
3. octal: Their composition of numbers are 0,1,2,3,4,5,6,7. When encountering 8 in decimal number, it will hit the ceiling and become 10

There is still more to learn for the technique of the value changing between these numeral systems. However, I think there is no need for me to do so by now. Just focusing on the concept itself would be fine.

1. Hex: `0x` and then the number, and the case of the letter doesn'y matter just like our normal habit.
2. binary:`0b` and then the number
3. octal:`0o` and then the number
4. other numeral sytem: for other system, there is no such supports. we have to use the function `parseInt`
1. by default for 10
2. vary from 2 to 36

built-in function for rounding

1. Math.floor: for round down
2. Math.ceil: for rounD up
3. Math.round: rounds to the nearest integer
4. Math.trunc: Removes anything after the decimal point without rounding

run to the appointed layer of digit. E.g., we want to 1.01234 run to 2 digit, which is only 1.01.

1. method 1: Multiply-and-divide.

2. method 2: toFixed(n)

(1) This rounds up or down to the nearest value, similar to `Math.round`

(2) that result of `toFixed` is a string

(3) If the decimal part is shorter than required, zeroes are appended.

1. situation 1

2. situation 2

(1) This is the innate limits for the numeral system. For decimal numbers, it can distinguish 1/10 or 1/20 easilym but are the result of 1/3 would be 0.333333...... It also happens the same to binary numbers, it can recognize 1/2 with no problem, but for 1/10 or 1/20, it will become endless fractions like 1/3 is decimal systems.

(2) Many programming languages have this kind of limits as well.

(3) SOLUTION 1

A. the solution can't be solved completely, for it is the innate feature of the language itself, we can merely use some little trick to stop this from happening.

B. toFixed(n)

(4) SOLUTION 2

(5) conclusion

Totally evading fractions is rarely possible.

To avoid the problem completely isn't promissed, just like the example we've seen of the solution 2. Hence, we could just cut them off once and for all, which is the solution 1

3. situation 3

comes from its limis of 64-bit format, and it's unsolvable.

4. situation 4

two zeros can exist at the same time, and the distinct is unnoticeable

1. NaN is one of a numeric value

2. Test if a thing is NaN by using isNaN(value), it would simply convert the value into number and test if it belongs to NaN

3. it is needed because "=== NaN" won't work, for NaN equals to nothing, including itself.

1. convert the value to a number, and returns true/false depending on whether it is finite.

2. usage: to see whether the a string value is a regular number

Please note that an empty or a space-only string is treated as `0` in all numeric functions including `isFinite`.

1. built-in for comparing values in === way,
2. `Object.is(a, b)` is the same as `a === b`
3. NaN works unlike normal ===: Object.is(NaN, NaN) === true
4. distinguish the difference of 0 and -0: Object.is(0, -0) === false
5. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called SameValue).

It is need becuase for using normal numeric conversion, such as +(unary plus) ot Number(), it fails if the value itself can not completely converted to a number. However, in reality, there are many situations that require this kind of "imperfect" numeric conversion. For example, `"100px"` or `"12pt"` in CSS, or “19€” for repesenting the amount of the currency.

parseInt and parseFloat are able to read numbers until they can't and return the value it has read. The former is for reading integer, and the latter is able to read the floating numbers.

Other math functions

1. Math.random(): return a random number from 0 to 1.
2. Math.max( , , )
3. Math.min( , , )
4. Math.pow(n, power)

Three kinds of quotes

1. ""
2. ''
3. ``

(1) able to embed expressions in the string with \${…}

(2) able to support multiple line quotes

(3) able to support "template function" by using func`string` (rarely used)

1. \n means next line

1. They all start with \, which is also called escape character
2. backslash `\` serves for the correct reading of the string by JavaScript, then disappears. The in-memory string has no `\`.
1. quotes: in order not to become the string (but if the choice of the quote character is not the same, it can be used safely.)
2. unicode: special symbols
3. the backlash in the string: \\ (if there is only one, the engine would just ignore it.)
1. str.length (not str.length(), it is a property not a function)
2. example
1. The first character starts from 0 position

2. an alternative: charAt()

3. if there is no position, it would return undefined for str[]

1. you can't replace the old string of the variable with new one using normal way

2. you can only create a new one and assign it to the old one and the old one would be replaced

"....".toLowerCase()

“….”.toUpperCase()

1. “….”[0].toLowerCase()
2. e.g., alert( ‘Interface’[0].toLowerCase() ); // ‘i’
1. str.indexOf(‘……’)
2. in which position the substring is found, and return the order of the position
3. return -1 if it can't be found
4. It will start from the 0
5. the case matters
1. advanced functionality of part 1
2. str.indexOf(‘……’, order)
3. looking for the occurence other than the first
1. finding all occerences
1. NOT number converts the number to a 32-bit integer
2. for 32-bit integers `~n` equals `-(n+1)`.
1. pratical use of the searching: indexOf in the “if” test, to alert if we found one

(1) the test `if ( ~str.indexOf("...") )` is truthy only if the result of `indexOf` is not `-1`.

(2) it's not recommended to use in this kind of unobvious way, but it is widely used in the old code.

(3) `if (~str.indexOf(...))` reads as “if found”.

1. way better than the method of part 4
2. "......".includes(...)
3. returns true/false
1. advanced functionality of part 5
2. “……”.includes(…, order)
3. true/false for the position to start searching from
1. memorizing this method would be enough
2. Returns the part of the string from `start` to (but not including) `end`
3. str.slice(start [, end])

4. If there is no second argument, then `slice` goes till the end of the string:

5. Negative values for `start/end` are also possible. They mean the position is counted from the string end:

6. The specified order of the interval must be arranged from front to back

1. str.substring(start [, end])
2. Returns the part of the string between `start` and `end`(not included), which is almost the same as `slice`
3. it allows `start` to be greater than `end`. (the arrangement of order isn't restricted, the reversed is still the same as the non-reserved one)

3. Negative arguments are (unlike slice) not supported, they are treated as `0`.

1. str.substr(start [, length])
2. Returns the part of the string from `start`, with the given `length`instead of the ending position

3. The first argument may be negative, to count from the end

1. character-by-character: A lowercase letter is always greater than the uppercase:
2. word comparison: Letters with diacritical marks are “out of order”
1. Each character has a corresponding numeric code, and it is allowed to get the code of the character back
2. str.codePointAt(pos)

(1) different case letters have different codes

3. String.fromCodePoint(code)

(1) We can also add Unicode characters by their codes using `\u` followed by the hex code:

1. due to its nature, the algorithm for string comparison would be more complex.
2. the solution: ‘.......’.localeCompare(‘.......’)

(1) a special method to compare strings in different languages, following their rules.

• Returns a negative number if `str` is less than `str2`.
• Returns a positive number if `str` is greater than `str2`.
• Returns `0` if they are equivalent.

#

order (4): Introduction to the blockchain technology by Ethereum, developer perspective

# Fundamental topics

• Blocks — The way transactions are batched to ensure state is synchronised across all actors#
• The Ethereum Virtual Machine (EVM) — The EVM handles all the computation on the Ethereum network#
• Gas — Computational power required to process transactions, paid for in ETH by transaction senders#
• Nodes and clients — The individuals participating in the network and the software they run to verify transactions#
• Networks — Implementations of Ethereum including test networks
• Block explorers — A way to read data about transactions, accounts, blocks and the network
• Mining — The way transactions are processed and blocks are created

###The four parts with # are completed. In the beginning, I thought there is no need for reorganize the learning by writing them down, but now I think it's necessary to do so. I would move to the beginning and redo them again, but just for the topics that are exclusively for Ethereum. There are some key but complex concepts that I have much more to work on.

For the parts I haven't completely grasped, it's better to find more realted materials.###

#

Taiwanese. Male. Ximena is my daughter(future). Capable of self-taught anything (a bit overconfidence). Face the ordeal of listening to the sage on the stage.

Love podcasts or audiobooks? Learn on the go with our new app.

## Ximena Han

Taiwanese. Male. Ximena is my daughter(future). Capable of self-taught anything (a bit overconfidence). Face the ordeal of listening to the sage on the stage.