-
Notifications
You must be signed in to change notification settings - Fork 0
#12 π Type Conversion in JS | | String Conversion | Numeric Conversion | Boolean Conversion
*****************************Tutorial Start π₯ ********************************
Data(**)->variable(let a=5)
variables hold your data
variables jo data hold karega uska aik type hoga jisko hum data type bhi kehte hai.(data type)
what kind of data stored by variables is represented by data type
- Num
- string
- boolean
- Array
- object
Automatic type conversion/ Implicit type conversion
Bhut baar operators and function voo automatically convert kar dete hai value ko sahi data type mai.
- Example: alert()function automatically (bydefault) convert kar deta hai value ko string me.
Bhut saare function() aisee hai jo automatically convert kar dete hai values ko shai datatype me.
Manually Type Conversion/ Explicit type conversion
Lekin bhut baar humko khud jaruat padti hai convert karne ki manually.
- String conversion(convert value into string)
<!-- 1.JAVASCRIPT CODE SNIPPET HERE, please check repo for code access -->
- Numberic conversion(convert x type value into number)
<!-- 1.JAVASCRIPT CODE SNIPPET HERE, please check repo for code access -->
- Boolean conversion(convert x type value into boolean)
<!-- 1.JAVASCRIPT CODE SNIPPET HERE, please check repo for code access -->
- parseInt() function
let pI = parseInt(floatValue); //covert decimal value into numbers console.log(pI); console.log(typeof pI);
- parseFloat() function
let pF = parseFloat(floatValue); //convert string into float values console.log(pF); console.log(typeof pF);
- undefined ko convert kiya too it becames => NaN(not a number)
- null = 0
- true = 1
- false = 0
console.log(Number(false)); //output 0 console.log(Number(undefined)); //NaN console.log(Number(null)); // 0; console.log(Number(true)); // 1
string agar more than 1 character "xyz" ki ye too output hamesa true dega and agar 0 character "" hai too output hamesa false dega
and agar isme number hota =1; too ye true deta and agar = 0; hota too false deta
and agar isme negative value hota =-30; too ye true deta and agar = +30 ; hota too bhi true return karega
*****************************Tutorial End π ********************************
FOllow me on Github