DEV Community

Cover image for Dummy learn Javascript
Ha Tuan Em
Ha Tuan Em

Posted on

Dummy learn Javascript


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!

Top comments (0)