Fiero Code
JavaScript Cheat Sheet
Common JavaScript commands, and what each one does.
Use the links to jump to a group, or search the page for a command.
Output & Display
console.log()
console.log("Hello, world!");Prints a message in the browser's console.
Like talking to the computer secretly.
alert()
alert("Welcome!");Pops up a message box.
Like shouting a message to your visitor.
Variables
let age = 12; // can change later
const pi = 3.14; // cannot changeVariables are like labeled boxes to store info.
Data Types
let score = 100; // Number
let name = "Lucy"; // String
let isHappy = true; // BooleanNumbers for math, strings for text, booleans for yes/no.
Operators
5 + 3 // 8
5 > 3 // true
5 === "5" // false (strict check)Math, comparisons, and logic tools.
Functions
function greet() {
console.log("Hello!");
}
greet(); // call itA recipe you can reuse anytime.
Loops
for loop
for (let i = 1; i <= 5; i++) {
console.log(i);
}Repeats a block of code a set number of times.
Like counting on fingers until you stop.
while loop
let count = 1;
while (count <= 3) {
console.log(count);
count++;
}Keeps looping while condition is true.
Like "keep going until the rule breaks."
for…of loop
let fruits = ["apple", "banana", "cherry"];
for (let fruit of fruits) {
console.log(fruit);
}Loops through each item in an array.
Like going through each item in a shopping list.
Objects
Creating an Object
let person = {
name: "Levi",
age: 6,
isStudent: true
};An object stores related information in key–value pairs.
Think of it like a backpack with labeled pockets.
Accessing Properties
console.log(person.name); // Levi
console.log(person["age"]); // 6Two ways to get values from objects.
Like asking "what's in the pocket labeled 'age'?"
Adding/Changing
person.grade = "1st";
person.age = 7;Add new keys or update existing ones.
Common Methods
String Methods
"Hello".toUpperCase(); // "HELLO"
"Hello".toLowerCase(); // "hello"
"Hello World".includes("World"); // trueHandy tools for working with text.
Array Methods
let colors = ["red", "blue"];
colors.push("green"); // add to end
colors.pop(); // remove last
colors.shift(); // remove first
colors.unshift("pink"); // add to startLike adding/removing items from a list.
Math Methods
Math.random(); // random number 0–1
Math.floor(4.7); // 4
Math.ceil(4.2); // 5
Math.round(4.5); // 5Math helpers for rounding and randomness.
Number Conversion
parseInt("42"); // 42
parseFloat("3.14"); // 3.14Turns strings into numbers.
Interactivity with HTML
<p id="greeting">Hello</p>
<script>
document.getElementById("greeting").innerText = "Hi there!";
</script>Changes page content dynamically.
Like editing a webpage after it loads.
These commands are part of Fiero Code.
