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 => ?
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, undefiend
there 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:
- Any value (i.e null, number, string) * 0 => 0, except
undefined
. - String + number => "String + number"
- String - number => number
- String * number => NaN
- Boolean == 0 => true
- Null == undefined => true
- 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"
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"
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)