JavaScript
Category:
- Scripting Language
Progression
Introduction
JavaScript is huge, and as such, trying to compile my notes on EVERYTHING here is probably way out of scope for a blog like this. I will try to reduce my notes to bite-sized pieces of information that could ideally help someone who ends up here get moving in the right direction.
Variables
Declarations
const
let
var
(althoughvar
should be avoided in favor ofconst
orlet
)
Data Types
undefined
null
boolean
string
symbol
bigint
number
object
All variables and function names are case sensitive. Best practice in JavaScript is to use camelCase to declare our variables, as such:
const someVariable;
const anotherVariableName;
Operators
i++;
and i--;
can be used to increment or decrement a variable by 1, with no direct assignment required.
“Augmented” operations are a term to modify a value by different quantity than 1 by combining an operator and equals, as shown:
let myVar = 1;
myVar = myVar + 4; // 5
let otherVar = 1;
otherVar += 4; // 5
Valid operators for this operation include +
-
*
/
and more.
%
is referred to as “remainder” in JavaScript and not “modulus”. The operation is similar to modulus, but does not work properly with negative numbers.
Documentation
// In-line comment
/* Multi
line
comment */
/**
* JSDoc comment
* @see {@link https://jsdoc.app/|JSDoc Syntax}
*/
Strings
Strings can marked with "
or '
. To use quote marks within a string, you can either mix one set of quote symbols per level like 'They said, "Hello!" to the world.'
, or escape identical quotes with \
, like "I am a \"double quoted\" string"
.
Single and double quotes are functionally identical in JavaScript.
The string datatype has a .length
parameter exposed, and individual letters can be accessed like an array:
let myStr = "Test";
console.log(myStr[0]); // "T"
Arrays
Arrays can be flat, or nested to create multi-dimensional arrays:
let myArray = [1,2,3];
let myMultiDimArr = [[1,2,3],[4,5,6],[7,8,[9,10]]]
Arrays have a .push()
method exposed that allows us to take one or more parameters and “push” them onto the end of the array (after the index array.length-1
).
The .pop()
method allows us to “pop” a value off the end of the array (at the index array.length-1
) and assign it to a value.
let myPop = myArr.pop();
Similar to .pop()
, .shift()
removes the first element of the array (at index 0).