JavaScript Language Basics

Source: Internet
Author: User

the basic syntax of JS
  /*Multi-line comments **/        //single-line comment//variable assignment defaults to a newline character as a terminator with a semicolon as the ending symbol        vari; I=10; S= "Hello"; varb=true; Console.log (i,typeofi);//Number typeConsole.log (s),typeofs);//String TypeConsole.log (b,typeofb);//Boolean type        //define an array        vararr=[11,222, "Hello"]; Console.log (arr,typeofarr); //Undefined type        varabc//1 Declaration unassigned, Get undefined 2 function no return valuealert (ABC); Alert (typeofabc
operator
// calculation operator: +-*/%  + +--      var i=0;      I+=1;    // i=i+1      ret=i++;     // i=i+1  First assigns the value to calculate the ret=++i again      ;       // i=i+1  Calculate the re-assignment first  // = = = All equals      Console.log ("1" ==1)   // true     Console.log ("1" ===1)   //  false
String Object
    //How to create:       vars=NewString ("Hello"); varS2= "Hello2"; //Properties and Methods        vars= "Hello World";        Console.log (s.length);        Console.log (S.touppercase ()); Console.log (S.charat (3));//get characters by indexConsole.log (S.indexof ("w"));//get an index by characterConsole.log (S.substr (1,3));//string truncation, substr (starting position, truncated length)Console.log (s.substring (1,3));//string truncation, substr (starting position, truncated position)Console.log (S.slice (1,3));//string truncation, substr (starting position, truncated position)        varRet=s.split ("");//slicingConsole.log (ret)
Array Object
    //creating an Array object        vararr=[111,222,333]; varArr2=NewArray (111,222,333);        Console.log (Arr.tolocalestring ()); Console.log (typeofarr.tolocalestring ()); //Array Method        vararr=[11,223,34, "Hello",true]; Console.log (arr[3]); //Join Method        varRet=arr.join (""); Console.log (ret);//Reverse Reverse Sort sort        vars=[100,23,44,12]; functionmysort (x, y) {returnX-y} console.log (S.reverse ()); //[ +,--]Console.log (S.sort (Mysort));//[A. , Max.]//push adds a value pop delete        vararr=[11,22,33]; Arr.push (45,67);        Console.log (arr);        Console.log (Arr.pop ()); Console.log (arr);
Function Object
// Definition of a         function        function function name () {           function body         }        //  anonymous function        ( function () {            Functional body        } )();

JavaScript Language Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.