Last Updated: December 26, 2018
·
645
· Chao Yang

javascript very basic.

  1. variables

    var varString = "abc";
    var varNumber = 123;
    var varArray = ["abc",123];
  2. function

    var varFunction = function ()
    {
        code code code;
    };
  3. control flow

    // if-else
    if (condition) {
        code code code;
    } else if {
        code code code;
    } else {
        code code code;
    }
    //while
    while (condition) {
        code code code;
    }
    //do-while
    do {
        code code code;
    } while (condition)
    //for
    for (initial ; condition ; incrementor) {
        code code code;
    }
  4. Math

    var NumberSeven = Math.floor(7.14);
    var RandomBetweenZeroAndOne = Math.randome();
    //A random number between 1 and 10
    var randomNumber = Math.floor(Math.random() * 9 + 1);
  5. oo

    //Literal notation
    var varObject = function () {
        this.property1= property1;
        this.property2 = property2;
        this.method = function () {
            code code code;
            code code code;
        }
    };
    
    //Constructor notation
    var varObject = new Object();
    varObject.property1 = property1;
    varObject.property2 = property2;
    varObject.method = function () {
        code code code;
        code code code;
    }

1 Response
Add your response

@marti1125
Thanks,
I am learning how to code javascript @ http://www.codecademy.com, it rocks.

over 1 year ago ·