hey guys how are you all today in this post I am going to give you the source code of my video called arrays and conversion in JavaScript so let's begin:-
// ARRAYS in javascript
console.log("This is arrays in js")
var arr1 = [32,34,23,23,234,"this",
{
name:"Gautam",
class : "8th",
rollno: 6
}
]
console.log(arr1)
console.log(arr1[5])
console.log(arr1.length)
console.log(arr1.concat('main'));
console.log(arr1);
// // ----------------------------------------------------
// CONVERSION IN JAVASCRIPT
// Converting in to strings
var num1 = 45;
console.log(num1);
var str1 = String(num1);
console.log(str1);
console.log(typeof str1);
console.log(typeof num1);
var number1 = 33453434;
console.log(number1,typeof number1);
var string1 = number1.toString();
console.log(string1,typeof string1);
// -----------------------------------------------------------
// Converting to numbers
// Way1:
var myname = "01010d101"; // this will return NaN which means not a number because it includes alphabets.
console.log(myname,typeof myname);
var mynameinnum = Number(myname)
console.log(mynameinnum, typeof mynameinnum)
var boolean1 = true;
console.log(boolean1, typeof boolean1)
console.log(Number(boolean1),typeof Number(boolean1));
var boolean2 = false;
console.log(boolean2,typeof boolean2)
console.log(Number(boolean2),typeof Number(boolean2));
var num1 = 32;
console.log(num1)
var float1 = parseFloat(num1);
console.log(float1);
var float2 = 23423.324444444;
console.log(float2)
var int1 = parseInt(float2);
console.log(int1)
I hope that you liked this post.
Like, share, subscribe to the channel and the video.
Thank You.
Comments
Post a Comment