Learn JavaScript: Introduction Cheatsheet
Learn JavaScript: Introduction Cheatsheet
Introduction
Assignment Operators
console.log(number);
// Prints: 120
String Interpolation
// String interpolation
`Tommy is ${age} years old.`;
about:srcdoc Page 1 of 8
2/11/25, 1:13 AM
Variables
Variables are used whenever there’s a need to store a const currency = '$';
piece of data. A variable contains data that can be
let userIncome = 85000;
used in the program elsewhere. Using variables also
ensures code re-usability since it can be used to
replace the same value in multiple places. console.log(currency + userIncome + '
is more than the average income.');
// Prints: $85000 is more than the
average income.
Unde!ned
about:srcdoc Page 2 of 8
2/11/25, 1:13 AM
Declaring Variables
Template Literals
Template literals are strings that allow embedded let name = "Codecademy";
expressions, ${expression} . While regular
console.log(`Hello, ${name}`);
strings use single ' or double " quotes, template
literals use backticks instead. // Prints: Hello, Codecademy
let
let Keyword
about:srcdoc Page 3 of 8
2/11/25, 1:13 AM
const
const Keyword
String Concatenation
console.log(displayText);
// Prints: Your credit card bill is due
on May 30th.
console.log()
console.log()
JavaScript
about:srcdoc Page 4 of 8
2/11/25, 1:13 AM
Methods
Methods return information about an object, and are // Returns a number between 0 and 1
called by appending an instance with a period . ,
Math.random();
the method name, and parentheses.
Built-in Objects
Numbers
Numbers are a primitive data type. They include the let amount = 6;
set of all integers and "oating point numbers.
let price = 4.99;
String .length
.length
The .length property of a string returns the let message = 'good nite';
number of characters that make up the string.
console.log(message.length);
// Prints: 9
console.log('howdy'.length);
// Prints: 5
about:srcdoc Page 5 of 8
2/11/25, 1:13 AM
Data Instances
Booleans
Booleans are a primitive data type. They can be let lateToWork = true;
either true or false .
Math.random()
Math.random()
Math.floor()
Math.floor()
In JavaScript, single-line comments are created with // This line will denote a comment
two consecutive forward slashes // .
about:srcdoc Page 6 of 8
2/11/25, 1:13 AM
Null
Strings
Strings are a primitive data type. They are any let single = 'Wheres my bandit hat?';
grouping of characters (letters, spaces, numbers, or
let double = "Wheres my bandit hat?";
symbols) surrounded by single quotes ' or double
quotes " .
Arithmetic Operators
about:srcdoc Page 7 of 8
2/11/25, 1:13 AM
Multi-line Comments
let baseUrl =
'localhost/taxwebapp/country';
Print Share
about:srcdoc Page 8 of 8