JavaScript - Introduction Cheatsheet
JavaScript - Introduction Cheatsheet
Introduction
Assignment Operators
[Link](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
let userIncome = 85000;
in the program elsewhere. Using variables also ensures
code re-usability since it can be used to replace the
same value in multiple places. [Link](currency + userIncome + ' is
more than the average income.');
// Prints: $85000 is more than the
average income.
[Link] 1/7
7/5/24, 5:57 PM 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
[Link](`Hello, ${name}`);
single ' or double " quotes, template literals use
backticks instead. // Prints: Hello, Codecademy
[Link] 2/7
7/5/24, 5:57 PM 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
[Link](count); // Prints: undefined
variable is optional. A let variable will contain
undefined if nothing is assigned to it. count = 10;
[Link](count); // Prints: 10
const Keyword
String Concatenation
[Link](displayText);
// Prints: Your credit card bill is due
on May 30th.
[Link]()
[Link] 3/7
7/5/24, 5:57 PM 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
[Link]();
method name, and parentheses.
Built-in Objects
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 let message = 'good nite';
of characters that make up the string.
[Link]([Link]);
// Prints: 9
[Link]('howdy'.length);
// Prints: 5
[Link] 4/7
7/5/24, 5:57 PM Learn JavaScript: Introduction Cheatsheet | Codecademy
Data Instances
Booleans
Booleans are a primitive data type. They can be either let lateToWork = true;
true or false .
[Link]()
[Link]()
In JavaScript, single-line comments are created with // This line will denote a comment
two consecutive forward slashes // .
Null
[Link] 5/7
7/5/24, 5:57 PM Learn JavaScript: Introduction Cheatsheet | Codecademy
Strings
Strings are a primitive data type. They are any grouping let single = 'Wheres my bandit hat?';
of 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';
[Link] 6/7
7/5/24, 5:57 PM Learn JavaScript: Introduction Cheatsheet | Codecademy
Print Share
[Link] 7/7