Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="Different types of Data">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>Datatypes (Simple and Complex)</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- /*
- * Datatypes:
- *
- * 0. A data type is a classification identifying types of data such as string, boolean or numbers. It determines the possible values for that particular type.
- * To be able to operate on variables, it is important to know something about the type.
- * They are categorized into two categories, Simple/Primitive and Comples. There are six primitives
- * There are six simple (primitives) datatypes: strings, numbers, Boolean, null, undefined, and NaN.
- * Primitive datatypes can only hold single value. Complex datatypes are objects, arrays, and function.
- */
- //1. Numbers //
- var a =123;
- console.log(a); // prints 123
- var a =12.3;
- console.log(a); // prints 12.3
- //Number types are numerical values that can be both integer and floating point numbers. They can also be positive or negative.//
- //2.String //
- var a = "Superman";
- console.log(a); // prints Superman//
- var a = 'Hip Hop Hooray';
- console.log(a); // prints Hip Hop Hooray//
- var b ="Superman returns";
- console.log(b); // prints Superman returns//
- /*String datatypes is a series of characters written in double or single quotes. Strings are used
- *for storing and manipulating text. Strings are immutable.
- */
- //3.Boolean //
- console.log(1 > 2); // returns false
- var color = "blue";
- console.log(color === "blue"); // returns true
- //Booleans has only two values: true or false.
- //4.Array //
- var color = ["red", "blue", "orange"];
- console.log(color); // prints the array//
- // Arrays are used to store multiples values in a variable. You create an array with [].
- console.log(color[1]); // prints blue
- //Arrays elements are numbered, starting with 0.
- color.push('black'); // Adds 'black' to the array.
- console.log(color);
- console.log(color.length); // prints 4//
- // Use length to find the total number of elements.//
- //5.Object //
- var man = {
- firstName: 'Long',
- lastName: 'Nguyen',
- age: 2,
- };
- /* Objects are key value pairs. Access object properties with objectName["propertyName"] or
- * objectName.property.Name. */
- console.log(man.age); // prints 2//
- //6.Functions //
- /* Functions are a block of code that performs a particular task. It allows the code to
- *be ran multiple times with different arguments to produce different results.
- *It is defined by function() {} */
- function sum(a, b) {
- return a + b; // code to be executed. //
- };
- console.log(sum(1, 1));// prints 2 //
- //7.Undefined //
- // When a variable is declared but the value is not assigned it is undefined.//
- var x; // unassigned variable //
- console.log(x); // returns undefined //
- //8. null //
- /* Has no value or is empty. Difference between undefined and null is that null
- * intentionally has no value. */
- var empty = null;
- // console.log(empty);// returns nothing//
- //9. NaN //
- /* Not a Number. Nan is the result of doing impossible math with other datatypes.
- //10.Infinity and -Infinity //
- /*Numeric value representing infinity. Value that is greater than any other number.
- *Also a producting of diving by 0. */
- var beyond = 1/ 0 ; // returns Infinity //
- console.log(beyond);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*
- * Datatypes:
- *
- * 0. A data type is a classification identifying types of data such as string, boolean or numbers. It determines the possible values for that particular type.
- * To be able to operate on variables, it is important to know something about the type.
- * They are categorized into two categories, Simple/Primitive and Comples. There are six primitives
- * There are six simple (primitives) datatypes: strings, numbers, Boolean, null, undefined, and NaN.
- * Primitive datatypes can only hold single value. Complex datatypes are objects, arrays, and function.
- */
- //1. Numbers //
- var a =123;
- console.log(a); // prints 123
- var a =12.3;
- console.log(a); // prints 12.3
- //Number types are numerical values that can be both integer and floating point numbers. They can also be positive or negative.//
- //2.String //
- var a = "Superman";
- console.log(a); // prints Superman//
- var a = 'Hip Hop Hooray';
- console.log(a); // prints Hip Hop Hooray//
- var b ="Superman returns";
- console.log(b); // prints Superman returns//
- /*String datatypes is a series of characters written in double or single quotes. Strings are used
- *for storing and manipulating text. Strings are immutable.
- */
- //3.Boolean //
- console.log(1 > 2); // returns false
- var color = "blue";
- console.log(color === "blue"); // returns true
- //Booleans has only two values: true or false.
- //4.Array //
- var color = ["red", "blue", "orange"];
- console.log(color); // prints the array//
- // Arrays are used to store multiples values in a variable. You create an array with [].
- console.log(color[1]); // prints blue
- //Arrays elements are numbered, starting with 0.
- color.push('black'); // Adds 'black' to the array.
- console.log(color);
- console.log(color.length); // prints 4//
- // Use length to find the total number of elements.//
- //5.Object //
- var man = {
- firstName: 'Long',
- lastName: 'Nguyen',
- age: 2,
- };
- /* Objects are key value pairs. Access object properties with objectName["propertyName"] or
- * objectName.property.Name. */
- console.log(man.age); // prints 2//
- //6.Functions //
- /* Functions are a block of code that performs a particular task. It allows the code to
- *be ran multiple times with different arguments to produce different results.
- *It is defined by function() {} */
- function sum(a, b) {
- return a + b; // code to be executed. //
- };
- console.log(sum(1, 1));// prints 2 //
- //7.Undefined //
- // When a variable is declared but the value is not assigned it is undefined.//
- var x; // unassigned variable //
- console.log(x); // returns undefined //
- //8. null //
- /* Has no value or is empty. Difference between undefined and null is that null
- * intentionally has no value. */
- var empty = null;
- // console.log(empty);// returns nothing//
- //9. NaN //
- /* Not a Number. Nan is the result of doing impossible math with other datatypes.
- //10.Infinity and -Infinity //
- /*Numeric value representing infinity. Value that is greater than any other number.
- *Also a producting of diving by 0. */
- var beyond = 1/ 0 ; // returns Infinity //
- console.log(beyond);
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement