Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- //dataTypes:complex
- //Objects, Arrays, and Functions are complex types, and one characteristic of complex types is that they can be of any size.
- //complex types are copied by reference.
- //stored as reference when assigned to a variable
- //Objects can contain any number of key/value pairs.
- //Arrays can contain any number of elements, and
- //Functions can encapsulate any number of statements.
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //array:
- //collection of value as a list
- //arrays are used to store multiple values in a single variable, using the [ ] sign, with a comma(,)between values.
- var num1=1;
- var num2=2;
- var num3=3;
- var num4=4;
- var num5=5;
- var arrayNum=[1,2,3,4,5];
- var car1="acuro";
- var car2="beebee";
- var car3="chena";
- var car4="toto";
- var car5="wolfwolf";
- var arrayCar=["acura","beebee","chena","toto","wolfwolf"];
- // you can add more element if needed
- //array are zero indexed, it start its count from 0(zer0)
- //arrayCar[0] is the first element "acura"
- //arrayCar[1] is the second element "beebee"
- //arrayCar[2] is the third element "chena"
- //arrayCar[3] is the fourth element "toto"
- //arrayCar[4] is the fifth element "wolfwolf" or you can use (arrayCar.length-1) to get the last element
- //you can modify the array
- //methods modify the array:
- //.pop() removes the last element from an array
- arrayCar.pop(); //=>["acura","beebee","chena","toto"];
- //.push() method adds a new element to the end of an array
- arrayCar.push("yoda"); //=>["acura","beebee","chena","toto","wolfwolf","yoda]
- //.shift() method removes the first array element and "shifts" all other elements to a lower index.
- arrayCar.shift(); //=>["beebee","chena","toto","wolfwolf"]
- //.unshift() method adds a new element to an array at the beginning, and "unshifts" older elements:
- arrayCar.unshift("cat"); //=>["cat","acura","beebee","chena","toto","wolfwolf"]
- //.toString() converts an array to a string seperated by comma.
- arrayCar.toString(); //=>"acura,beebee,chena,toto,wolfwolf"
- //.join() method also joins all array elements into a string.
- //It behaves just like toString(), but in addition you can specify the separator:
- arrayCar.join("."); //=>"acura.beebee.chena.toto.wolfwolf"
- //.sort() method sorts an array alphabetically:
- arrayCar.sort(); //=>"acura.beebee.chena.toto.wolfwolf"
- //.reverse() method reverses the elements in an array.
- arrayCar.reverse(); //=>["wolfwolf", "toto", "chena", "beebee", "acura"]
- //.length property of an array returns the length of an array (the number of array elements).
- arrayCar.length(); //=>5
- //changing the value of an array
- arrayCar[0]="poopoo"; //=>["poopoo","beebee","chena","toto","wolfwolf"];
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //object:
- // object literal are created with {}
- //In JavaScript, arrays use numbered indexes.
- //In JavaScript, objects use named indexes.
- // collection of key:value pair seperated by a colon(:)
- var objectTest={car:"doodoo",
- color:"clear",
- speed:5,
- rival:["yoda","chekke"]};
- // You can access object properties in two ways:dot. and bracket [] notation
- objectTest.car; //=>"doodoo"
- objectTest["car"]; //=> "doodoo"
- //but use dot notation. its better for the enviroment.
- objectTest.color; //=>"clear"
- objectTest.rival; //=>["yoda", "chekke"]
- objectTest.rival[0]; //=>"yoda"
- //You can add new properties to an existing object by simply giving it a value.
- objectTest.cost=135;
- //The delete keyword deletes a property from an object:
- delete objectTest.color;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //function:
- //perform action on data and return it
- //Functions allow us to encapsulate a block of code, and execute that block of code whenever we want and how ever many times we want when its called.
- //Two phases of using Functions:1)declaration/definition: creating the Function.2)invocation/calling/executing/applying: using the Function.
- function functionNameHere(parameter) { "code to be excuted goes here";}
- var functionTest0=100;
- function functionTest1(a,b){return a+b;} //=>a+b
- function functionTest2(a,b,c){return a+b;} //=>a+b
- function functionTest3(a,b,c,d){return a+b+c+d+e+a;} //=>error "ReferenceError: e is not defined
- function functionTest4(){return "hello"+functionTest0+"world";} //=>hello100world
- //Accessing a function without () will return the function definition instead of the function result:
- functionTest4; //=>function functionTest(){return "hello"+functionTest0+"world";}
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">//dataTypes:complex
- //Objects, Arrays, and Functions are complex types, and one characteristic of complex types is that they can be of any size.
- //complex types are copied by reference.
- //stored as reference when assigned to a variable
- //Objects can contain any number of key/value pairs.
- //Arrays can contain any number of elements, and
- //Functions can encapsulate any number of statements.
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //array:
- //collection of value as a list
- //arrays are used to store multiple values in a single variable, using the [ ] sign, with a comma(,)between values.
- var num1=1;
- var num2=2;
- var num3=3;
- var num4=4;
- var num5=5;
- var arrayNum=[1,2,3,4,5];
- var car1="acuro";
- var car2="beebee";
- var car3="chena";
- var car4="toto";
- var car5="wolfwolf";
- var arrayCar=["acura","beebee","chena","toto","wolfwolf"];
- // you can add more element if needed
- //array are zero indexed, it start its count from 0(zer0)
- //arrayCar[0] is the first element "acura"
- //arrayCar[1] is the second element "beebee"
- //arrayCar[2] is the third element "chena"
- //arrayCar[3] is the fourth element "toto"
- //arrayCar[4] is the fifth element "wolfwolf" or you can use (arrayCar.length-1) to get the last element
- //you can modify the array
- //methods modify the array:
- //.pop() removes the last element from an array
- arrayCar.pop(); //=>["acura","beebee","chena","toto"];
- //.push() method adds a new element to the end of an array
- arrayCar.push("yoda"); //=>["acura","beebee","chena","toto","wolfwolf","yoda]
- //.shift() method removes the first array element and "shifts" all other elements to a lower index.
- arrayCar.shift(); //=>["beebee","chena","toto","wolfwolf"]
- //.unshift() method adds a new element to an array at the beginning, and "unshifts" older elements:
- arrayCar.unshift("cat"); //=>["cat","acura","beebee","chena","toto","wolfwolf"]
- //.toString() converts an array to a string seperated by comma.
- arrayCar.toString(); //=>"acura,beebee,chena,toto,wolfwolf"
- //.join() method also joins all array elements into a string.
- //It behaves just like toString(), but in addition you can specify the separator:
- arrayCar.join("."); //=>"acura.beebee.chena.toto.wolfwolf"
- //.sort() method sorts an array alphabetically:
- arrayCar.sort(); //=>"acura.beebee.chena.toto.wolfwolf"
- //.reverse() method reverses the elements in an array.
- arrayCar.reverse(); //=>["wolfwolf", "toto", "chena", "beebee", "acura"]
- //.length property of an array returns the length of an array (the number of array elements).
- arrayCar.length(); //=>5
- //changing the value of an array
- arrayCar[0]="poopoo"; //=>["poopoo","beebee","chena","toto","wolfwolf"];
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //object:
- // object literal are created with {}
- //In JavaScript, arrays use numbered indexes.
- //In JavaScript, objects use named indexes.
- // collection of key:value pair seperated by a colon(:)
- var objectTest={car:"doodoo",
- color:"clear",
- speed:5,
- rival:["yoda","chekke"]};
- // You can access object properties in two ways:dot. and bracket [] notation
- objectTest.car; //=>"doodoo"
- objectTest["car"]; //=> "doodoo"
- //but use dot notation. its better for the enviroment.
- objectTest.color; //=>"clear"
- objectTest.rival; //=>["yoda", "chekke"]
- objectTest.rival[0]; //=>"yoda"
- //You can add new properties to an existing object by simply giving it a value.
- objectTest.cost=135;
- //The delete keyword deletes a property from an object:
- delete objectTest.color;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //function:
- //perform action on data and return it
- //Functions allow us to encapsulate a block of code, and execute that block of code whenever we want and how ever many times we want when its called.
- //Two phases of using Functions:1)declaration/definition: creating the Function.2)invocation/calling/executing/applying: using the Function.
- function functionNameHere(parameter) { "code to be excuted goes here";}
- var functionTest0=100;
- function functionTest1(a,b){return a+b;} //=>a+b
- function functionTest2(a,b,c){return a+b;} //=>a+b
- function functionTest3(a,b,c,d){return a+b+c+d+e+a;} //=>error "ReferenceError: e is not defined
- function functionTest4(){return "hello"+functionTest0+"world";} //=>hello100world
- //Accessing a function without () will return the function definition instead of the function result:
- functionTest4; //=>function functionTest(){return "hello"+functionTest0+"world";}
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement