Skip to content

Instantly share code, notes, and snippets.

View goodbedford's full-sized avatar

goodbedford goodbedford

View GitHub Profile
@goodbedford
goodbedford / js-assignment-operators.js
Last active April 2, 2016 14:07
intro-js js-assignment-operators.js
// = the equal sign is the assignment operator;
var a = 10; // number ten is assigned to variable a;
var b = 20;
var c = 12;
a = c; // a is 12
console.log("a: " + a);
a = c = b; // a is 20, c is 20, b is 20
console.log("a: " + a);
@goodbedford
goodbedford / js-comparison-operator.js
Created March 31, 2016 21:19
js-comparison-operator.js
// strict equality comparison operator is the triple equals ( === )
// this checks for exact equality in value and type
var a = 4;
var b = 4;
var c = "4";
// both a and b are numbers
console.log("a === b is:", a === b);
// arithmetic operators are your standard math operators
// we have addition + , subtraction - , multiplication * , division /, modulo/remainder %,
var a = 10;
var b = 5;
var c = 22;
// addition +
console.log("a + b =", a + b);
// relational operators compare greater than, less than, or equal to
var a = 10;
var b = 5;
// a is greater than b
console.log("a is greater than b:", a > b);
// b is not greater than a
console.log("b is greater than a:", b > a);
// order of precedence are the rules for the order in which value gets evaluated
console.log("1 * 2 + 3 * 2 =", 1 * 2 + 3 * 2);
console.log("1 * 2 + 3 * 2 * 5 =", 1 * 2 + 3 * 2 *5);
console.log("5 +1 * 2 + 3 * 2 * 5 =", 5 +1 * 2 + 3 * 2 * 5 );
var str = "I am a string variable that is declared and defined";
console.log("I am a string"); // I am a string to console
console.log(str); // I am a string variable that is declared and defined
// this is a single line comment
var a = 5; // single line comment after legit code
var a = 5; // single line comment, commenting out the code
/* this is a multi-line comment
this is a multi-line comment
*/
var a; // is undefined
var b = "name"; // is defined
console.log("A:" + a); // prints undefined
console.log("B:" + b); // prints "name"
console.log("C" + c); // ReferenceError not defined
var someArray = [1, 2, 3, [11, 22, 33]];
console.log("array object:", someArray);
console.log("array to string:", someArray.toString());
var listOfFruit = ["apples", "pear", "lemons", "lychee"];
// what will the # of items be?
console.log("I have", listOfFruit.length, "things on my list.");