This series of articles focuses on common uses of JavaScript, suitable for junior-level front-end developers, and can be compared to Typescript's series of articles.
First, we introduce the functions of JavaScript variables and common variables, and the code is as follows:
//variables Common functionsvari=3.1415926;varIpoint2=i.tofixed (2); Console.log ("Take two digits after the decimal point:" +ipoint2);varI2=i.toprecision (2); Console.log ("Total two-bit:", i2);vari3=3.9; Console.log ("Fetch nearest whole number:" +Math.Round (i3)); Console.log ("Take the smallest integer:" +Math.floor (i3)); Console.log ("Random Generate Number:" +math.random ());//Type Conversionsvarnumber=100;varNumberstr=number.tostring ();if(typeofnumberstr=== "string") {Console.log ("Convert to String:" +numberstr);}varnumberstring1= "100";varnumber1=Number (numberstring1);if(typeofnumber1=== "Number") {Console.log ("Convert to Number:" +number1);}//null, NULL, undefined judgmentvarName= "Caojian";varsex=NULL;if(name) {Console.log ("Your name is:" +name);}if(Sex) {Console.log ("Your sex is:" +sex);}varnames=["Caojian", "HCC"];if(names) { for(vari=0;i<names.length;i++) {Console.log ("The names are:" +Names[i]); }}//Array ManipulationvarArr=NewArray (); Arr.push ("C #"); Arr.push ("Python"); Arr.push ("Java"); Arr.push ("TypeScript"); Arr.pop (); Console.log ("After the last one is introduced, change the original array:" +arr); Arr.sort (); Console.log ("Change the original array after sorting:" +arr);varArrstr=arr.join (";"); Console.log ("Arrays are combined as strings using connectors:" +arrstr);vararr1=NewArray (); Arr1.push ("HTML5"); Arr1.push ("JavaScript");vararrarr1=Arr.concat (arr1);varArrarr1str=arrarr1.join (";"); Console.log ("Two arrays concatenated after a string:" +arrarr1str); Arr.splice (0,2, "C # backend language", "Java Back-end language"); Console.log ("Replace 2 elements with a new value starting at index 0:" +arr);varNewarr1=arr.slice (2,3); Console.log ("Starting at index 2, take 3-2 elements:" +newarr1);varArrmap=arr.map (function(i) {return"Language:" +i;}); Console.log ("Project each element to operate:" +arrmap);varNewarr2=arr.filter (function(i) {returni[0]=== "C";}); Console.log ("The element at the beginning of the letter C is:" +newarr2);varAllc=arr.every (function(i) {returni[0]=== "C";}); Console.log ("Each element starts with C:" +ALLC);varSomec=arr.some (function(i) {returni[0]=== "C";}); Console.log ("There are elements that start with C:" +Somec);//ConstantsConst animal={category: "Cat", age:20};Try{animal. Age=21;}Catch(Error) {Console.log (error.message);}finally{Console.log ("After changing a property value for a constant:" +Animal. Category+" "+Animal. age);}Try{Animal={category: "Cat", age:22};}Catch(Error) {Console.log (error.message);}
Welcome to join QQ Group discussion: 573336726
Variable of 01-javascript