JavaScript FreeCodeCamp Flashcards
// This is a comment
Single line comment
/* This is a multi-line comment */
multiple line comment
NaN
not a number
sometimes referred to as floating point numbers or floats
decimal numbers
myVar % 2 = 1
Checks to see if myVar is odd. 1 = odd, 0 = even
var sampleStr = “Alan said, "Peter is learning Javascript".”;
use \ to signal that “ should appear inside the string
\n
newline
\t
tab
\b
word boundary
\f
form feed
firstName.length
returns the number of characters in the string in firstName
zero-based indexing
programming languages start counting at 0
var lastLetter = firstName[firstName.length - 1];
returns the last character in the string firstName
multi-dimensional array
[[“Bulls, 23], [“White Sox”, 45]]
myArray[0] = 15;
arrays are mutable and entries can be changed freely
myArray[3][0][1]
equals the #3 entry, #0 entry in that array, and #1 entry in that array
myArray.push(4);
appends 4 to the end of the array
myArray.pop();
removes the last element from an array and returns that element
myArray.shift();
removes the first element from an array and returns it
myArray.unshift(4);
adds element to the beginning of the array
function testFun(param1, param2) { }
creates a reusable function that takes parameters (arguments)
==
equality operator. Returns true if both values are equal.
===
Strict equality operator. Will not perform data type conversion.
typeof 3
returns “number”
typeof “3”
returns “string”
!=
Inequality operator. Returns true if values are not equal.
!==
Strict Inequality operator. Will not convert data types.
&&
Logical and operator. Returns true if both operands are true
||
Logical or operator. Returns true if either of the operands are true.
var myObj = { prop1: "val1", prop 2: "val2" };
creates an object
myObj.prop1
returns the value in prop1 in the object myObj
myObj[“Space Name”]
returns the value in “Space Name” in the object myObj
delete ourDog.bark;
removes “bark” property from object ourDog
myObj.hasOwnProperty(“propName”);
Returns true if the object has the given property
JSON
JavaScript Object Notation
while (i < 5) {
ourArray.push(i);
i++;
}
while loop. Runs while a specified condition is true.
for (initialization; condition; final expression) { }
a for loop that runs for a specified number of times
var i = 0; do { ourArray.push(i); i++; } while (i < 5);
Do-while loop. Runs the code at least once before checking the condition to see if it continues.
Math.random()
function that generates a random decimal number between 0 (inclusive) to 1 (exclusive)
Math.floor(num)
function that rounds the number down to a whole number
Math.floor(Math.random() * 20)
gives a whole number between 0 and 19
Math.floor(Math.random() * (max - min + 1)) + min
returns a whole number between min and max, inclusive
parseInt(“”)
function that parses a string and returns the corresponding integer
parseInt(string, radix)
Parses the string and returns an integer. The radix specifies the base number of the string. The radix can be an integer between 2 and 36.
condition ? statement-if-true : statement-if-false;
conditional operator. A one line if-else expression