Javascript Cheatsheet
Javascript Cheatsheet
console.log()
console.log() console.log('Hi there!');
// Prints: Hi there!
Math.random();
.
// Math is the built-in object
let amount = 6;
let price = 4.99;
.length
.length let message = 'good nite';
console.log(message.length);
// Prints: 9
console.log('howdy'.length);
// Prints: 5
1 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc
Math.random()
Math.random() console.log(Math.random());
// Prints: 0 - 0.9999999999999999
Math.floor()
Math.floor() console.log(Math.floor(5.95));
// Prints: 5
let x = null;
null
2 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc
// Addition
+
5 + 5
-
* // Subtraction
/ 10 - 5
% // Multiplication
5 * 10
// Division
10 / 5
// Modulo
10 % 5
/*
/* */
The below configuration must be
changed before deployment.
*/
3 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc
console.log(number);
// Prints: 120
let age = 7;
// String interpolation
`Tommy is ${age} years old.`;
undefined var a;
undefined console.log(a);
// Prints: undefined
4 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc
// Examples of variables
let name = "Tammy";
const found = false;
var age = 3;
console.log(name, found, age);
// Prints: Tammy false 3
var age;
let weight;
var
let const numberOfFingers = 20;
const
let
let let count;
let console.log(count); // Prints: undefined
let
count = 10;
undefined
console.log(count); // Prints: 10
const
const numberOfColumns = 4;
const
numberOfColumns = 8;
const
// TypeError: Assignment to constant
variable.
5 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc
console.log(displayText);
// Prints: Your credit card bill is due on
May 30th.
6 of 6 6/14/2023, 10:02 AM