Last active
March 1, 2018 01:58
-
-
Save emmasamuel/a1723f2e58651f46717c6d0de8683797 to your computer and use it in GitHub Desktop.
javascript// source https://jsbin.com/vazofuh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h1{ | |
| color: deeppink; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = 1; | |
| console.log(typeof x); | |
| //fractional | |
| var y = 2.4; | |
| //5.3 * 10^8 | |
| var z = 5.3e8; | |
| console.log(z); | |
| //max min in JS | |
| var max = Number.MAX_VALUE; | |
| console.log(max); | |
| var min = Number.MIN_VALUE; | |
| console.log(min); | |
| //aritimetic operation | |
| var a = 4 + 9; | |
| console.log(a); | |
| a = 3 * 4; | |
| console.log(a); | |
| a = y - x; | |
| console.log(a); | |
| console.log(12 / 4); | |
| var b = 3; | |
| //b = b + 2; | |
| //b = b + 1; | |
| //b = b - 100; | |
| b += 2; | |
| console.log(b); | |
| //b += 1; | |
| b ++; | |
| console.log(b); | |
| //b -= 1; | |
| b --; | |
| console.log(b); | |
| //operator precedence | |
| var c = 4 * (5 + 3); | |
| console.log(c); | |
| var d = ++ c; | |
| console.log(c); | |
| console.log(d); | |
| var e = c ++; | |
| console.log(c); | |
| console.log(e); | |
| //var f = 2 + 3 - 1; | |
| // f ++; | |
| //console.log(f); | |
| //remainder operator | |
| var f = 17 % 3; // this means that 17 divide by 3 will remain 2 | |
| //exponent operator | |
| var g = 3 ** 4; //3x3x3x3: return the base to the exponent power | |
| console.log(g); | |
| // infinity | |
| var h = Infinity; | |
| console.log(h); | |
| console.log(3/0); | |
| //NaN: means Not a Number | |
| var i = 0/0; //no meaningful result | |
| console.log(i); | |
| //power method | |
| var j = Math.pow(2,53); | |
| console.log(j); | |
| //big number | |
| var k = Math.pow(2, 2000); | |
| console.log(k); | |
| //parse a string and return an integer | |
| var number = '3'; | |
| console.log(parseInt(number)); | |
| console.log(parseInt('not a number')); | |
| console.log(typeof parseInt('not a number')); | |
| //how to turn strings into numbers is like this parseInt (x); if your x = "3" | |
| //string | |
| var job = 'web developer'; | |
| console.log(job); | |
| //escape the normal process and treat quotation marks as punctuation marks. | |
| var greeting = 'Hello, I\'m glad to see you'; | |
| //special characters | |
| // new line | |
| var quote = "this is \n a new line"; | |
| console.log(quote); | |
| var quote = "this is a new line"; | |
| console.log(quote); | |
| quote = "Here is a \t a tab"; | |
| console.log(quote); | |
| //concatenation | |
| var firstname = 'Bill'; | |
| var lastname = 'Gates'; | |
| var fullname = firstname + " " + lastname + "."; | |
| console.log(fullname); | |
| var s = 'apple'; | |
| //method work with the primitive type and object type. will be covered in details later | |
| console.log(s.length); | |
| console.log(s.charAt(2)); | |
| console.log(s.indexOf('l')); | |
| console.log(s.lastIndexOf('p')); | |
| //BOOLEANS | |
| // is x greater-than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x > y; | |
| console.log(z); | |
| // is x less than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x < y; | |
| console.log(z); | |
| // is x equal to y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x == y; | |
| console.log(z); | |
| //is x equal to y, and are they the same value? | |
| var x = 3; | |
| var y = 5; | |
| var z = x === y; | |
| console.log(z); | |
| // logical operators | |
| // this is the continuation of the eualation above. | |
| // is x lesser than y and greater than 0? | |
| z= (x < y) && (x > 0); | |
| console.log(z); | |
| // the (!) mark means the opposite of true which is the answer. | |
| z = !(x < 10); | |
| console.log(z); | |
| // && is stronger | |
| z = false && true || true; | |
| console.log(z); | |
| //unary operator | |
| // to use this method you must add question marks so now instead of true or false it will use pass and fail. | |
| z = x > 2 ? 'pass' : 'fail'; | |
| console.log(z); | |
| // logical operation with non booleans | |
| console.log('banana' == false); | |
| z = 'banana' && 'apple'; | |
| console.log(z); | |
| var fruit; | |
| console.log(fruit); | |
| console.log(fruit == false); | |
| z = fruit || 'apple'; | |
| console.log(z); | |
| console.log(''== false); | |
| z = '' || 'apple'; | |
| console.log(z); | |
| z = '' && false; | |
| console.log(z); | |
| z = 0 && false; | |
| console.log(z); | |
| //null and undefinded | |
| var x; // undefined are variables with no value. and is also a primitive TYPES. | |
| console.log(x); | |
| console.log(typeof x); | |
| var y = null; // null can be assigned as a value as a representation of no value and it return as an obeject when printed. | |
| console.log(y); | |
| console.log(typeof y); | |
| // type coercion | |
| var z = "1" + 5; // string "1" turns 5 into a string "5" the answer is "1""5"....15 and is a string. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "1" - 5;// it prints as a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "one" * 2;// NaN is still a number. with this kind of equalation it cant be a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = 2 * null; | |
| console.log(z); | |
| console.log(typeof z); | |
| console.log(0 == false); | |
| console.log("" == false); | |
| console.log(null == false); | |
| console.log(undefined == false); | |
| //undefined ==null | |
| console.log(undefined == null); | |
| console.log(undefined == undefined); | |
| console.log(null == undefined); | |
| console.log(null == null); | |
| // objects quick overveiw | |
| //object = collection of properties | |
| var myPhone = { | |
| make: "apple", | |
| model: "Iphone 7", | |
| warranty: 12, | |
| colour: "gold" | |
| } | |
| console.log(myPhone); | |
| console.log(myPhone.model); | |
| // change properties | |
| myPhone.model = "Iphone 6"; | |
| console.log(myPhone); | |
| // add new property | |
| myPhone.storage = "64 go"; | |
| console.log(myPhone); | |
| //delete property | |
| delete myPhone.storage; | |
| console.log(myPhone); | |
| //now let's do something interesting | |
| var x = 1; | |
| var y = x; | |
| x = 2; | |
| console.log(y);// y stores his first value which is 1. | |
| // now let do that with objects | |
| var myOtherPhone = myPhone; | |
| console.log(myOtherPhone); | |
| //CHANGE PHONE COLOR | |
| myPhone.color = "grey"; | |
| console.log(myPhone); | |
| console.log(myOtherPhone); //this only work if your make one object equal to the other object like x=y. | |
| //Arrays quick overveiw | |
| var shoppingList = ["bread", "egg", "milk"]; | |
| console.log(shoppingList); | |
| console.log(shoppingList[1]);//this is to know the number of a particular string number. | |
| console.log(shoppingList.length);// this is wa to know the numbers of strings in an arrays. | |
| //prompt('message'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title> javascript</title> | |
| <style id="jsbin-css"> | |
| h1{ | |
| color: deeppink; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1> Booleans </h1> | |
| <script type="text/javascript" src="code.js"></script> | |
| <script id="jsbin-javascript"> | |
| var x = 1; | |
| console.log(typeof x); | |
| //fractional | |
| var y = 2.4; | |
| //5.3 * 10^8 | |
| var z = 5.3e8; | |
| console.log(z); | |
| //max min in JS | |
| var max = Number.MAX_VALUE; | |
| console.log(max); | |
| var min = Number.MIN_VALUE; | |
| console.log(min); | |
| //aritimetic operation | |
| var a = 4 + 9; | |
| console.log(a); | |
| a = 3 * 4; | |
| console.log(a); | |
| a = y - x; | |
| console.log(a); | |
| console.log(12 / 4); | |
| var b = 3; | |
| //b = b + 2; | |
| //b = b + 1; | |
| //b = b - 100; | |
| b += 2; | |
| console.log(b); | |
| //b += 1; | |
| b ++; | |
| console.log(b); | |
| //b -= 1; | |
| b --; | |
| console.log(b); | |
| //operator precedence | |
| var c = 4 * (5 + 3); | |
| console.log(c); | |
| var d = ++ c; | |
| console.log(c); | |
| console.log(d); | |
| var e = c ++; | |
| console.log(c); | |
| console.log(e); | |
| //var f = 2 + 3 - 1; | |
| // f ++; | |
| //console.log(f); | |
| //remainder operator | |
| var f = 17 % 3; // this means that 17 divide by 3 will remain 2 | |
| //exponent operator | |
| var g = 3 ** 4; //3x3x3x3: return the base to the exponent power | |
| console.log(g); | |
| // infinity | |
| var h = Infinity; | |
| console.log(h); | |
| console.log(3/0); | |
| //NaN: means Not a Number | |
| var i = 0/0; //no meaningful result | |
| console.log(i); | |
| //power method | |
| var j = Math.pow(2,53); | |
| console.log(j); | |
| //big number | |
| var k = Math.pow(2, 2000); | |
| console.log(k); | |
| //parse a string and return an integer | |
| var number = '3'; | |
| console.log(parseInt(number)); | |
| console.log(parseInt('not a number')); | |
| console.log(typeof parseInt('not a number')); | |
| //how to turn strings into numbers is like this parseInt (x); if your x = "3" | |
| //string | |
| var job = 'web developer'; | |
| console.log(job); | |
| //escape the normal process and treat quotation marks as punctuation marks. | |
| var greeting = 'Hello, I\'m glad to see you'; | |
| //special characters | |
| // new line | |
| var quote = "this is \n a new line"; | |
| console.log(quote); | |
| var quote = "this is a new line"; | |
| console.log(quote); | |
| quote = "Here is a \t a tab"; | |
| console.log(quote); | |
| //concatenation | |
| var firstname = 'Bill'; | |
| var lastname = 'Gates'; | |
| var fullname = firstname + " " + lastname + "."; | |
| console.log(fullname); | |
| var s = 'apple'; | |
| //method work with the primitive type and object type. will be covered in details later | |
| console.log(s.length); | |
| console.log(s.charAt(2)); | |
| console.log(s.indexOf('l')); | |
| console.log(s.lastIndexOf('p')); | |
| //BOOLEANS | |
| // is x greater-than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x > y; | |
| console.log(z); | |
| // is x less than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x < y; | |
| console.log(z); | |
| // is x equal to y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x == y; | |
| console.log(z); | |
| //is x equal to y, and are they the same value? | |
| var x = 3; | |
| var y = 5; | |
| var z = x === y; | |
| console.log(z); | |
| // logical operators | |
| // this is the continuation of the eualation above. | |
| // is x lesser than y and greater than 0? | |
| z= (x < y) && (x > 0); | |
| console.log(z); | |
| // the (!) mark means the opposite of true which is the answer. | |
| z = !(x < 10); | |
| console.log(z); | |
| // && is stronger | |
| z = false && true || true; | |
| console.log(z); | |
| //unary operator | |
| // to use this method you must add question marks so now instead of true or false it will use pass and fail. | |
| z = x > 2 ? 'pass' : 'fail'; | |
| console.log(z); | |
| // logical operation with non booleans | |
| console.log('banana' == false); | |
| z = 'banana' && 'apple'; | |
| console.log(z); | |
| var fruit; | |
| console.log(fruit); | |
| console.log(fruit == false); | |
| z = fruit || 'apple'; | |
| console.log(z); | |
| console.log(''== false); | |
| z = '' || 'apple'; | |
| console.log(z); | |
| z = '' && false; | |
| console.log(z); | |
| z = 0 && false; | |
| console.log(z); | |
| //null and undefinded | |
| var x; // undefined are variables with no value. and is also a primitive TYPES. | |
| console.log(x); | |
| console.log(typeof x); | |
| var y = null; // null can be assigned as a value as a representation of no value and it return as an obeject when printed. | |
| console.log(y); | |
| console.log(typeof y); | |
| // type coercion | |
| var z = "1" + 5; // string "1" turns 5 into a string "5" the answer is "1""5"....15 and is a string. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "1" - 5;// it prints as a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "one" * 2;// NaN is still a number. with this kind of equalation it cant be a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = 2 * null; | |
| console.log(z); | |
| console.log(typeof z); | |
| console.log(0 == false); | |
| console.log("" == false); | |
| console.log(null == false); | |
| console.log(undefined == false); | |
| //undefined ==null | |
| console.log(undefined == null); | |
| console.log(undefined == undefined); | |
| console.log(null == undefined); | |
| console.log(null == null); | |
| // objects quick overveiw | |
| //object = collection of properties | |
| var myPhone = { | |
| make: "apple", | |
| model: "Iphone 7", | |
| warranty: 12, | |
| colour: "gold" | |
| } | |
| console.log(myPhone); | |
| console.log(myPhone.model); | |
| // change properties | |
| myPhone.model = "Iphone 6"; | |
| console.log(myPhone); | |
| // add new property | |
| myPhone.storage = "64 go"; | |
| console.log(myPhone); | |
| //delete property | |
| delete myPhone.storage; | |
| console.log(myPhone); | |
| //now let's do something interesting | |
| var x = 1; | |
| var y = x; | |
| x = 2; | |
| console.log(y);// y stores his first value which is 1. | |
| // now let do that with objects | |
| var myOtherPhone = myPhone; | |
| console.log(myOtherPhone); | |
| //CHANGE PHONE COLOR | |
| myPhone.color = "grey"; | |
| console.log(myPhone); | |
| console.log(myOtherPhone); //this only work if your make one object equal to the other object like x=y. | |
| //Arrays quick overveiw | |
| var shoppingList = ["bread", "egg", "milk"]; | |
| console.log(shoppingList); | |
| console.log(shoppingList[1]);//this is to know the number of a particular string number. | |
| console.log(shoppingList.length);// this is wa to know the numbers of strings in an arrays. | |
| //prompt('message'); | |
| </script> | |
| <script id="jsbin-source-css" type="text/css">h1{ | |
| color: deeppink; | |
| }</script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var x = 1; | |
| console.log(typeof x); | |
| //fractional | |
| var y = 2.4; | |
| //5.3 * 10^8 | |
| var z = 5.3e8; | |
| console.log(z); | |
| //max min in JS | |
| var max = Number.MAX_VALUE; | |
| console.log(max); | |
| var min = Number.MIN_VALUE; | |
| console.log(min); | |
| //aritimetic operation | |
| var a = 4 + 9; | |
| console.log(a); | |
| a = 3 * 4; | |
| console.log(a); | |
| a = y - x; | |
| console.log(a); | |
| console.log(12 / 4); | |
| var b = 3; | |
| //b = b + 2; | |
| //b = b + 1; | |
| //b = b - 100; | |
| b += 2; | |
| console.log(b); | |
| //b += 1; | |
| b ++; | |
| console.log(b); | |
| //b -= 1; | |
| b --; | |
| console.log(b); | |
| //operator precedence | |
| var c = 4 * (5 + 3); | |
| console.log(c); | |
| var d = ++ c; | |
| console.log(c); | |
| console.log(d); | |
| var e = c ++; | |
| console.log(c); | |
| console.log(e); | |
| //var f = 2 + 3 - 1; | |
| // f ++; | |
| //console.log(f); | |
| //remainder operator | |
| var f = 17 % 3; // this means that 17 divide by 3 will remain 2 | |
| //exponent operator | |
| var g = 3 ** 4; //3x3x3x3: return the base to the exponent power | |
| console.log(g); | |
| // infinity | |
| var h = Infinity; | |
| console.log(h); | |
| console.log(3/0); | |
| //NaN: means Not a Number | |
| var i = 0/0; //no meaningful result | |
| console.log(i); | |
| //power method | |
| var j = Math.pow(2,53); | |
| console.log(j); | |
| //big number | |
| var k = Math.pow(2, 2000); | |
| console.log(k); | |
| //parse a string and return an integer | |
| var number = '3'; | |
| console.log(parseInt(number)); | |
| console.log(parseInt('not a number')); | |
| console.log(typeof parseInt('not a number')); | |
| //how to turn strings into numbers is like this parseInt (x); if your x = "3" | |
| //string | |
| var job = 'web developer'; | |
| console.log(job); | |
| //escape the normal process and treat quotation marks as punctuation marks. | |
| var greeting = 'Hello, I\'m glad to see you'; | |
| //special characters | |
| // new line | |
| var quote = "this is \n a new line"; | |
| console.log(quote); | |
| var quote = "this is a new line"; | |
| console.log(quote); | |
| quote = "Here is a \t a tab"; | |
| console.log(quote); | |
| //concatenation | |
| var firstname = 'Bill'; | |
| var lastname = 'Gates'; | |
| var fullname = firstname + " " + lastname + "."; | |
| console.log(fullname); | |
| var s = 'apple'; | |
| //method work with the primitive type and object type. will be covered in details later | |
| console.log(s.length); | |
| console.log(s.charAt(2)); | |
| console.log(s.indexOf('l')); | |
| console.log(s.lastIndexOf('p')); | |
| //BOOLEANS | |
| // is x greater-than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x > y; | |
| console.log(z); | |
| // is x less than y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x < y; | |
| console.log(z); | |
| // is x equal to y? | |
| var x = 3; | |
| var y = 5; | |
| var z = x == y; | |
| console.log(z); | |
| //is x equal to y, and are they the same value? | |
| var x = 3; | |
| var y = 5; | |
| var z = x === y; | |
| console.log(z); | |
| // logical operators | |
| // this is the continuation of the eualation above. | |
| // is x lesser than y and greater than 0? | |
| z= (x < y) && (x > 0); | |
| console.log(z); | |
| // the (!) mark means the opposite of true which is the answer. | |
| z = !(x < 10); | |
| console.log(z); | |
| // && is stronger | |
| z = false && true || true; | |
| console.log(z); | |
| //unary operator | |
| // to use this method you must add question marks so now instead of true or false it will use pass and fail. | |
| z = x > 2 ? 'pass' : 'fail'; | |
| console.log(z); | |
| // logical operation with non booleans | |
| console.log('banana' == false); | |
| z = 'banana' && 'apple'; | |
| console.log(z); | |
| var fruit; | |
| console.log(fruit); | |
| console.log(fruit == false); | |
| z = fruit || 'apple'; | |
| console.log(z); | |
| console.log(''== false); | |
| z = '' || 'apple'; | |
| console.log(z); | |
| z = '' && false; | |
| console.log(z); | |
| z = 0 && false; | |
| console.log(z); | |
| //null and undefinded | |
| var x; // undefined are variables with no value. and is also a primitive TYPES. | |
| console.log(x); | |
| console.log(typeof x); | |
| var y = null; // null can be assigned as a value as a representation of no value and it return as an obeject when printed. | |
| console.log(y); | |
| console.log(typeof y); | |
| // type coercion | |
| var z = "1" + 5; // string "1" turns 5 into a string "5" the answer is "1""5"....15 and is a string. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "1" - 5;// it prints as a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = "one" * 2;// NaN is still a number. with this kind of equalation it cant be a number. | |
| console.log(z); | |
| console.log(typeof z); | |
| z = 2 * null; | |
| console.log(z); | |
| console.log(typeof z); | |
| console.log(0 == false); | |
| console.log("" == false); | |
| console.log(null == false); | |
| console.log(undefined == false); | |
| //undefined ==null | |
| console.log(undefined == null); | |
| console.log(undefined == undefined); | |
| console.log(null == undefined); | |
| console.log(null == null); | |
| // objects quick overveiw | |
| //object = collection of properties | |
| var myPhone = { | |
| make: "apple", | |
| model: "Iphone 7", | |
| warranty: 12, | |
| colour: "gold" | |
| } | |
| console.log(myPhone); | |
| console.log(myPhone.model); | |
| // change properties | |
| myPhone.model = "Iphone 6"; | |
| console.log(myPhone); | |
| // add new property | |
| myPhone.storage = "64 go"; | |
| console.log(myPhone); | |
| //delete property | |
| delete myPhone.storage; | |
| console.log(myPhone); | |
| //now let's do something interesting | |
| var x = 1; | |
| var y = x; | |
| x = 2; | |
| console.log(y);// y stores his first value which is 1. | |
| // now let do that with objects | |
| var myOtherPhone = myPhone; | |
| console.log(myOtherPhone); | |
| //CHANGE PHONE COLOR | |
| myPhone.color = "grey"; | |
| console.log(myPhone); | |
| console.log(myOtherPhone); //this only work if your make one object equal to the other object like x=y. | |
| //Arrays quick overveiw | |
| var shoppingList = ["bread", "egg", "milk"]; | |
| console.log(shoppingList); | |
| console.log(shoppingList[1]);//this is to know the number of a particular string number. | |
| console.log(shoppingList.length);// this is wa to know the numbers of strings in an arrays. | |
| //prompt('message'); | |
| </script></body> | |
| </html> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
learning the basics of javascript