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
// -----Loops----- // | |
/* For loops are great tools for iterating over individual elements within an array | |
to work with them. A for loop has three sections within its proceeding parentheses: an | |
initialization, conditional statement, and a final expression. The initialization phase | |
usually declares a variable. The conditional statement phase tells the loop when to stop, | |
and the final expression performs an action at the end, usually incrementing or | |
decrementing a counter: */ | |
"use strict"; |
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
// -----Control Flow----- // | |
/* If statements are used in Javascript to make decisions--whether to execute a following | |
code or not. An if statement first evaluates the boolean within parentheses and then executes | |
the code within curly braces if the boolean was true: */ | |
"use strict"; | |
if (typeof "Is this a string?" === "string") { | |
console.log("Yup, it was a string"); |
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
// -----Operators----- // | |
/* In Javascript, operators can perform a number of tasks. Unary operators take only one value: */ | |
"use strict"; | |
console.log(typeof 10); // "typeof" is a unary operator | |
console.log(!true); // "!" flips the following value, logging false | |
/* Binary operators can be placed between two values and return a new value: */ |
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
// -----Undefined, Null, NaN, Infinity, -Infinity----- // | |
/* Undefined and null are both special values that signify the absence of meaningful | |
data. Undefined is considered its own data type, but null is considered an object by Javascript, | |
which can be misleading. Null, more specifically, should represent the nonexistence of | |
something. */ | |
"use strict"; | |
console.log(typeof undefined); |
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
// -----Functions----- // | |
"use strict"; | |
name(); // ignore me for now *wink-wink* | |
/* Functions are first-class objects, "subprograms" and reusable code that can be "called" or | |
"invoked" at later times to produce a value or side-effect. To declare a simple function, first | |
begin with the keyword "function" followed by the name, parentheses, and curly braces. The | |
function body within the curly braces contains the sequence of statements to be executed when it |
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
// -----Objects----- // | |
/* An object, like an array, is a container for data, but an object stores key/value pairs | |
with curly braces. Almost every is considered an object except primitive values, including | |
strings, numbers, booleans, null, and undefined. Objects can be created in three ways: */ | |
"use strict"; | |
var obj1 = {}; // the literal method, creating an empty object assigned to the variable | |
console.log(obj1); |
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
// -----Arrays----- // | |
/* Arrays are list-like objects with a large number of mutational and accessible | |
methods. They can be assigned to variables and are enclosed with squar brackets: */ | |
"use strict"; | |
var exArray = ["I'm element 0", "I'm element 1", "Care to guess?"]; | |
/* As the example demonstrates, arrays are zero-based indexed, and elements can |
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
// -----Data Types: BOOLEAN----- // | |
/* A boolean is a data type that has one of two mutually | |
exclusive values: true or false. A boolean acts like an "on-off" | |
switch, where "true = on" and "false = off." They are used in | |
conjunction with comparion operators to evaluate expressions. | |
When comparing letters and non-alphnumeric characters, the | |
character will resolve to its Unicode number, which will be | |
used to make the comparison. When comparing strings, Javascript | |
compares individual characters from left to right. */ |
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
// -----Data Types: STRING----- // | |
/* Strings are character or textual data strung together enclosed | |
by either single or double quotes. */ | |
var stri = "I'm a sequence of character data!"; | |
console.log(stri); | |
/* Almost anything can be put within a string with the exception | |
of a number of special characters, such as the newline "\n" and |
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
// -----Data Types: NUMBER---- // | |
/* Numbers are simply numeric values used for arithmetic. | |
Whole integers and fractional numbers using decimal points | |
are permitted. With numbers of exceptional size, scientific | |
notation using "e" (exponent) is allowed: */ | |
// 2.998e8 = 2.998 × 10 to the 8th power = 299,800,000 | |
// -----Using Numbers for Arithmetic----- // |
NewerOlder