Variables

        var v1 = 0; // boolean
        var v2 = 'Hello World'; // string
        var v3 = 14; // integer
        var v4; // declared for later

        // another way to write variables
        var v1 = 0, // boolean
            v2 = 'Hello World', // string
            v3 = 14, // integer
            v4; // declared for later

Operations

        var o1 = 31 + 1, // Addition
            o2 = 31 - 1, // subtraction
            o3 = 2 * 31, // Multiplication
            o4 = 31 / 2, // Division
            o5 = 31 % 2, // Modulo - test if a number is odd or even
            o6, o7, o8; // Declare for use later

          o6 = o1++; // Add 1
          console.log( o1 + ' ++', o6 );

          o7 = o1--; // Minus 1
          console.log( o1 + ' --', o7 );

          o1 += 2; // plus 2
          console.log( o1 + ' +=', '2' );

          o1 -= 2; // minus 1
          console.log( o1 + ' -=', '2' );

          o1 *= 2; // multiply 2
          console.log( o1 + ' *=', '2' );

          o1 /= 2; // divide 2
          console.log( o1 + ' /=', '2' );

          o1 %= 2; // odd or even - 0 is even - 1 is odd
          console.log( o1 + ' %=', '2' );

Data Types

        var dt1, dt2, dt3, dt4, dt5, dt6;

        dt1 = 'Hello Wold';
        console.log( dt1 + ' is typeof', typeof(dt1));
        console.log( dt1 + ' isNaN?', isNaN(dt1));

        dt2 = 3;
        console.log( dt2 + ' is typeof', typeof(dt2));
        console.log( dt2 + ' isNaN?', isNaN(dt2));

        dt3 = true;
        console.log( dt3 + ' is typeof', typeof(dt3));

        dt4 = true;
        console.log( dt4 + ' is typeof', typeof(dt4));

        dt5 = function(){};
        console.log( dt5 + ' is typeof', typeof(dt5));

        dt6 = {};
        console.log( dt6 + ' is typeof', typeof(dt6));

        // dt7;
        console.log( 'dt7' + ' is typeof', typeof(dt7));

Booleans

        var b1, b2, b3, b4;

        b1 = 0;
        console.log('0' + ' =', b1);

        b2 = false;
        console.log('false' + ' =', b2);

        b3 = 1;
        console.log('1' + ' =', b3);

        b4 = true;
        console.log('true' + ' =', b4);

Logical Operators

        var lo;

        lo = !true;
        console.log('!true' + ' =', lo);

        lo = true && true;
        console.log('true && true' + ' =', lo);

        lo = true && false;
        console.log('true && false' + ' =', lo);

        lo = false && true;
        console.log('false && true' + ' =', lo);

        lo = false && false;
        console.log('false && false' + ' =', lo);

        lo = true || true;
        console.log('true || true' + ' =', lo);

        lo = true || false;
        console.log('true || false' + ' =', lo);

        lo = false || true;
        console.log('false || true' + ' =', lo);

        lo = false || false;
        console.log('false || false' + ' =', lo);

Comparison

        var lo;

        lo = 1 > 2;
        console.log('1 > 2' + ' =', lo);

        lo = 1 < 2;
        console.log('1 < 2' + ' =', lo);

        lo = 1 == 2;
        console.log('1 == 2' + ' =', lo);

        lo = 1 == 1;
        console.log('1 == 1' + ' =', lo);

        lo = 1 === 1;
        console.log('1 === 1' + ' =', lo);

        lo = 1 === '1';
        console.log('1 === "1"' + ' =', lo);

        lo = 1 != 2;
        console.log('1 != 2' + ' =', lo);

        lo = 1 !== '2';
        console.log('1 != "2"' + ' =', lo);

        lo = 1 != 2;
        console.log('1 != 2' + ' =', lo);

        lo = 1 >= 2;
        console.log('1 >= 2' + ' =', lo);

        lo = 1 <= 2;
        console.log('1 <= 2' + ' =', lo);

Arrays

        var a1, a2, a3, a4, a5;

        a1 = [];
        console.log('a1 is typof', typeof(a1));

        a1 = ['js', 'is', 'amazing'];
        console.log('add values to the array', a1);

        console.log('number of values in an array', a1.length);

        console.log('the first value is', a1[0]);

        console.log('the last value is', a1[ a1.length - 1 ]);

        a1.pop(0);
        console.log('remove the last value -', a1);

        a1.shift();
        console.log('remove the first value -', a1);

        a1.unshift('javascript');
        console.log('add new value to the front -', a1);

        a1.push('super', 'awesome');
        console.log('add new value to the end -', a1);

        a2 = a1.lastIndexOf("super");
        console.log('Find the position of super -', a2);

        a1[ a2 ] = 'f#ck@%*'
        console.log('Replace the the value of super -', a1);

        a1.sort();
        console.log('sort the array -', a1);

        a1.reverse();
        console.log('reverse the array -', a1);

        a3 = a1.slice(0,2);
        console.log('remove the first two values -', a3);

        a4 = a1.slice(2);
        console.log('remove the last two values -', a4);

        a1 = a3.concat(a4);
        console.log('glue the rwo arrays together -', a1);

        a1 = a1.join(' ');
        console.log('join the rwo arrays -', a1);

If and Else

        var ie1 = true,
            ie2 = 'blue',
            ie3;

        // simple if, and if the value is fasle we can do something else
        if( ie1 ){
          // lets do someting
          console.log('ie1 is true');
        } else {
          // so its false lets do something else
          console.log('ie1 is false');
        }

        // if its false, if its false again do something anyway
        if (ie2 === 'green') {
          console.log('ie2 is green');
        } else if (ie2 === 'red') {
          console.log('ie2 is red');
        } else {
          console.log('ie2 is not green or red its', ie2);
        };

        // if shorthand
        ie3 = ( ie2 === 'blue' ) ? 'Yes ie2 is blue' : 'No ie2 not blue'
        console.log(ie3);

Check if variable exists

        var cv1 ="",
            cv2 = 123,
            cv3 = undefined;
            cv4 = 'hellow world';

        if (cv1) {
          console.log('yes the cv1 variable exists');
        } else {
          console.log('there is no cv1 variable', cv1);
        };

        if (typeof cv1 !== 'undefined') {
          console.log('typeof cv1 is not "undefined"');
        } else {
          console.log('typeof cv1 is "undefined"');
        };

        if (typeof cv2 !== 'undefined') {
          console.log('typeof cv2 is not "undefined"');
        } else {
          console.log('typeof cv2 is "undefined"');
        };

        if (typeof cv3 !== 'undefined') {
          console.log('typeof cv3 is not "undefined"');
        } else {
          console.log('typeof cv3 is "undefined"');
        };

        if (typeof cv4 !== 'undefined') {
          console.log('typeof cv4 is not "undefined"');
        } else {
          console.log('typeof cv4 is "undefined"');
        };

Switch

        var s1 = 'ferrari',
            s2 = 'lamborghini',
            s3;

        // case is like asking a quesion
        switch (s1) {
          case 'audi':
            s3 = 'audi is not my favourite car';
            break;

          case s2:
            s3 = 's2 (lamborghini) is not my favourite car';
            break;

          default:
            s3 = 'my favourite car is a ' + s1;
            break;
        }

        console.log(s3);

Loops

        var l1 = ['html', 'js', 'css', 'php'],
            count;

        console.log('while Loop:');
        count = 0;

        while ( count < l1.length ) {
          console.log('while loop count', count + ' ' + l1[count]);
          count++;
        }

        console.log('do-while Loop:');
        count = 0;
        do {
          console.log('do-while loop count', count + ' ' + l1[count]);
          count++;
        } while ( count < l1.length );

        console.log('for Loop:');
        count = 0;
        for (var count = 0; count < l1.length; count++) {
          console.log('for loop count', count + ' ' + l1[count]);
        };

        console.log('for-in Loop:');
        count = 0;
        for ( count in l1 ){
          console.log('for in loop count', count + ' ' + l1[count]);
        }