Learn JavaScript - Introduction Cheatsheet - Codecademy
Learn JavaScript - Introduction Cheatsheet - Codecademy
Introduction
Assignment Operators
An assignment operator assigns a value to its left operand let number = 100;
based on the value of its right operand. Here are some of
them:
+= addition assignment // Both statements will add 10
-= subtraction assignment number = number + 10;
*= multiplication assignment number += 10;
/= division assignment
console.log(number);
// Prints: 120
String Interpolation
// String interpolation
`Tommy is ${age} years old.`;
Variables
Variables are used whenever there’s a need to store a const currency = '$';
piece of data. A variable contains data that can be used in
let userIncome = 85000;
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.
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 1/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
Undefined
Declaring Variables
Template Literals
Template literals are strings that allow embedded let name = "Codecademy";
expressions, ${expression} . While regular strings use
console.log(`Hello, ${name}`);
single ' or double " quotes, template literals use
backticks instead. // Prints: Hello, Codecademy
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 2/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
let Keyword
let creates a local variable in JavaScript & can be re- let count;
assigned. Initialization during the declaration of a let
console.log(count); // Prints: undefined
variable is optional. A let variable will contain
undefined if nothing is assigned to it. count = 10;
console.log(count); // Prints: 10
const Keyword
String Concatenation
console.log(displayText);
// Prints: Your credit card bill is due on
May 30th.
console.log()
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 3/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
JavaScript
Methods
Methods return information about an object, and are // Returns a number between 0 and 1
called by appending an instance with a period . , the
Math.random();
method name, and parentheses.
Built-in Objects
☝️
Math.random();
appending the object name with a period . , the method
// Math is the built-in object
name, and a set of parentheses.
Numbers
Numbers are a primitive data type. They include the set let amount = 6;
of all integers and floating point numbers.
let price = 4.99;
String .length
The .length property of a string returns the number of let message = 'good nite';
characters that make up the string.
console.log(message.length);
// Prints: 9
console.log('howdy'.length);
// Prints: 5
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 4/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
Data Instances
Booleans
Booleans are a primitive data type. They can be either let lateToWork = true;
true or false .
Math.random()
Math.floor()
In JavaScript, single-line comments are created with two // This line will denote a comment
consecutive forward slashes // .
Null
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 5/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
Strings
Strings are a primitive data type. They are any grouping of let single = 'Wheres my bandit hat?';
characters (letters, spaces, numbers, or symbols)
let double = "Wheres my bandit hat?";
surrounded by single quotes ' or double quotes " .
Arithmetic Operators
Multi-line Comments
let baseUrl =
'localhost/taxwebapp/country';
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 6/7
1/18/24, 10:41 AM Learn JavaScript: Introduction Cheatsheet | Codecademy
The remainder operator, sometimes called modulo, // calculates # of weeks in a year, rounds
returns the number that remains after the right-hand
down to nearest integer
number divides into the left-hand number as many times
as it evenly can. const weeksInYear = Math.floor(365/7);
Print Share
https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet 7/7