Dummy learn Javascript

hte305

Ha Tuan Em

Posted on December 3, 2020

Dummy learn Javascript

VALUES, TYPES AND OPERATOR

The values, types or operators in JAVASCRIPT as well as other programming languages. Have types of data as String, Number, Boolean, Array, etc... Have operators as "+, -, *, /, %". But each programming language has its own specialties. JAVASCRIPT just like that. Something stuck, something crazy, or something awesome that you meet when learning Javascript. And that why I see its interesting programming language. Here are the things of what I find out from books, the internet,...

Infinity 🌌🌌🌌,
As it's meaning full. This is a special value in Javascript. When you do math operator with this value you will get the values in all the time are Infinity or NaN. I don't know what is that useful for? And I am advisable not to do calculations with this variable. Because the Infinity values are not necessary for use in practical applications. If that is not required.

Comparison string 🚗 in 👨 or 👨 in 🚗,
In the real project. We can compare two strings values with each other without any problem (maybe I said that). In that, the comparison order takes precedence from "a-zA-Z0-9" in descending order.

Don't trust me, press F12 and make some calculates.

"a" > "A" => ?
"Z" > "0" => ?
"A" > "0" => ?
"a" > 0 => ?
Enter fullscreen mode Exit fullscreen mode

NaN values Not-A-Number 👽👾,

is a property of the global object or the global scope. NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it. And there are things of rules in NaN: number cannot be parsed parseInt("Tom Haland"), math operation where the result is not a number Math.sqrt(-100), operand of an argument is NaN 10 * NaN, Indeterminate form 0 * Infinity,

Empty values ☁,

null, undefiendthere are both special values in Javascript - sometimes you will see null in other programming language. But null in JS is different, that is object, don't trust me, checking typeof(null) === "object" you will see result make you amazing 😃😃😃. They are used for announcing an application variable that has not been declared or defined - like an owner who is away from home and of course we know whose home it is. By default, using null, undefiend is not too mandatory to use which type in a real project. just choose and use the type base on the design in your system.

Automatic type conversion 🚗=🚓,

Because Javascript is a form of dynamic programming languages. So the types of values from there also become more flexible to use. The values auto covert base on the right type value or left value or operator in whatever case. There are some rules:

  1. Any value (i.e null, number, string) * 0 => 0, except undefined.
  2. String + number => "String + number"
  3. String - number => number
  4. String * number => NaN
  5. Boolean == 0 => true
  6. Null == undefined => true
  7. Null == 0 => false

Short-Circuiting of logical operator 👌🤦‍♂️🤷‍♂️,

this operator is logical of two different data types with the purpose of being able to handle data. For &&, || with each of them make different results.

"Tom" && "That is Tom" => "That is Tom"
Enter fullscreen mode Exit fullscreen mode

The value starts from left to right side, if the value of left side is **truthy* type then the next value will be the result.

"Tom" || "Hill" => "Tom"
Enter fullscreen mode Exit fullscreen mode

In this case, which value is **truthy*, then take that value to result.

Truethy not include: false, 0, -0, 0n, “”, null, undefined, NaN

Absolute comparison 👩‍⚖️,

Absolute comparison between two types of values. Because JS is a dynamic programming language should be a means of comparison for sure as the final result must be absolutely accurate.

===, an ambiguity method of salvation of value type.

And as before, we have seen that null == undefined => true, but when adding an = sign, everything goes in a different direction, null === undefined => false.

=== is a righteous Judge. Everything is right and wrong. Will not tolerate any public under the jurisdiction of Judge ==.

I hope it helps a little bit.
Thanks for reading my post.
Have a nice day!

💖 💪 🙅 🚩
hte305
Ha Tuan Em

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

Functions in JavaScript
javascript Functions in JavaScript

October 13, 2021

Dummy learn Javascript
javascript Dummy learn Javascript

December 3, 2020