Sciextor

Security is Everyone's Job

JS Commands

Arrays & Strings

Array: let arr = [1, 2, 3];

Add Number to List: arr.push(4);

Take Off Last Number: arr.pop();

Joins & Returns String: arr.join("-");

Declare Stringlet str = "Hello world";

Uppercase: str.toUpperCase();

Lowercase: str.toLowerCase();

Replace: str.replace("world", "Bing");

Splits: str.split(" ");



Numbers

Declare Number: let num = 42;

Square Root: Math.sqrt(num);

Round to Nearest Int: Math.round(num);

Less or Equal to Int: Math.floor(num);

Greater or Equal to Int: Math.ceil(num);

Functions & Loops:

Create Function:

function name(parameter1, parameter2)

{return value;}

Calling Function: name(argument1, argument2);

For Loop:

for (let i = 0; i < 10; i++) {

}

While Loop:

while (condition) {

}

If/Else Loop:

if (condition) {

}

} else if (anotherCondition) {

}

} else {

}



DOM Manipulation

Returns Element by ID: document.getElementById(id);

Returns Class: document.getElementsByClassName(name);

Returns Selector: document.querySelector(selector);

Returns All Selector: document.querySelectorAll(selector);

Get/Set HTML Element: element.innerHTML;

Get/Set CSS Element: element.style.property;

Set Value: element.setAttribute(name, value);

Get Value: element.getAttribute(name);

Add Event Handler: element.addEventListener(event, function);

Remove Event Handler: element.removeEventListener(event, function);

Execute Function on Load: window.onload = function;

Return/Set URL: window.location.href;

Alert Message: window.alert(message);

Confirm Box: window.confirm(message);

Prompt Box: window.prompt(message, default);