typeof operator
===============
==> return "type" of the given data.
Syntax:
typeof(data-name) or
typeof data-name
JS ==> Dynamically Typed programming Language
Without the datatype the variable can be defined
and its type can be detected by the JS automatically at the run time.
Ex:
In Java:
datatype identifier = value;
ex: int a = 123;
In JavaScript:
let/var/const identifier = value;
Ex: let a = 123;
===============================================
Type Conversion:
================
==> also called as "Type casting".
==> to convert one primitive type to another type
Wrapping and Type Casting:
==========================
nextInt()
nextFloat() etc.
Syntax:
int a = Scanner-object.nextInt();
wrapping ==> convert a string to primitive type
==> can be classified into two types:
1) Implicit
===========
==> the system can automatically convert the data from one form to another form according to expression.
==> also called as "Automatic type casting".
a = 100
b = 3
c = 0;
c = a / b; // not the example for implicit
x = "hi"
y = 123
z = 0;
document.write("Type = "+typeof z);
z = x + y; // hi123
document.write("Type = "+typeof z);
2) Explicit
===========
Number() ==> to convert any primitive data to number type
// Number()
document.write(Number(0b110011001)+"
");
document.write(Number(0o654)+"
")
document.write(Number(0Xaf12)+"
")
document.write(Number(1.234)+"
")
document.write(Number('100')+"
")
document.write(Number('1.23')+"
")
document.write(Number("a")+"
")
document.write(typeof(NaN)+"
")
document.write(Number(true)+"
")
document.write(typeof(5736020100076201213214532541223445)+"
")
document.write(Number(null))
String()
========
==> any primitive type to string type
Boolean()
SI = P X T X R / 100;
5000 X 2.3 X 3.2/100
5999.9999
// String()
document.write(typeof(String(123)+"
")+"
")
// Boolean()
document.write(Boolean(100)+"
")
document.write(Boolean(-100)+"
")
document.write(Boolean(0)+"
")
document.write(Boolean('a')+"
")
document.write(Boolean('')+"
")