0% found this document useful (0 votes)
9K views

Javascript Cheat Sheet: Variables

This JavaScript cheat sheet provides concise summaries of key JavaScript concepts like variables, data types, mathematical expressions, objects, functions, and more. It includes code snippets and examples to demonstrate concepts like declaring variables, using different data types, logical operators, object literals, dot notation, and functions within objects. The cheat sheet was created by Pam Selle and is intended to keep helpful JavaScript hints and code snippets handy for reference.

Uploaded by

Lyd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9K views

Javascript Cheat Sheet: Variables

This JavaScript cheat sheet provides concise summaries of key JavaScript concepts like variables, data types, mathematical expressions, objects, functions, and more. It includes code snippets and examples to demonstrate concepts like declaring variables, using different data types, logical operators, object literals, dot notation, and functions within objects. The cheat sheet was created by Pam Selle and is intended to keep helpful JavaScript hints and code snippets handy for reference.

Uploaded by

Lyd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

 

JavaScript Cheat Sheet 


 
Use this cheat sheet to keep helpful hints and snippets handy. Handcrafted by Pam Selle. 
 
 
 
VARIABLES 
A variable is a variable because it changes! 
 
var oranges = 0; 
var oranges = ‘lots!’; 
var orangesAndBananas = 1; 

 
DATA TYPES 

How we store information in JavaScript 


 
 
Contained in quotes, quotes 
var bananas = “I have some bananas”; 
must match (single ‘ or 
Strings  var oranges = ‘Don\’t have oranges’; 
double “). Escape quotes with 
 

var numberOfBananas = 5; var 


Numbers  Hello old friends! 
numberOfOranges = 0; 

var haveBananas = true; var haveOranges =  Value of true or false, no 


Boolean 
false;  quotes 

Undefined  var strawberries;  No value assigned to it yet 

No quotes; a purposely 
Null  var pumpkins = null;  empty value (not the same as 
0 or undefined) 

 
 
   

 
 

MATHEMATICAL EXPRESSIONS + COMPARISONS  

+  Addition  ===  Equality 

-  Subtraction  !==  Inequality 

*  Multiplication  >  Greater than 

/  Division  >=  Greater than or equal to 

%  Modulus (remainder)  <  Less than 

++  Increment (increase by 1)  <=  Less than or equal to 

--  Decrement (decrease by 1)     

+=  Add to value (ex. +=2)     

-=  Subtract from value (ex -=3)     

 
LOGICAL OPERATORS AND IF/ELSE 
 
&&  and  var bananas = 5; 
var oranges = 2; 
if (bananas > 3 && oranges > 3){ 
console.log('Eat fruit!'); 

else { 
console.log(‘Go with Plan B!’); 

||   or  if (bananas < 2 || oranges < 2){ 


console.log('Buy fruit!'); 

!  not  if !(bananas >== 0){ 


console.log('How do you have negative 
bananas?'); 

JAVASCRIPT CHEATSHEET. Created by Pam Selle, inspired by work by Cat Farman. Used in GirlDevelopIt's 2013 JavaScript 
Course. Original cheat sheet ​here​. 

       
 

 
 

 
OBJECT LITERAL (OBJECTS) DOT NOTATION  

Accessing Information 
 
 
var kitten = {  var likes = kitten.likes; 
age: 1,  kitten.name = “Furball”; 
name: "Fluffy",   
likes: ["yarn", "snuggles"], 
color: “grey” 
}; 

 
 
OBJECTS IN FUNCTIONS 
 
var kitten = {  function aboutMyPets(pet) { 
name: “Fluffy”,  console.log(pet.name + “ is my pet ” + 
species: “cat”  pet.species); 
}  } 
aboutMyPets(kitten); 

 
FUNCTIONS IN OBJECTS (METHODS) 
 
var kitten = {  kitten.getName() 
name: “Fluffy”,   
species: “cat”, 
getName: function() { 
console.log(this.name); 

 
 
JAVASCRIPT CHEATSHEET. Created by Pam Selle, inspired by work by Cat Farman. Used in GirlDevelopIt's 2013 JavaScript 
Course. Original cheat sheet ​here​. 

       
 

 
 
 
 

 
 
STILL HAVE QUESTIONS? 
Email h
[email protected]​!  
 

JAVASCRIPT CHEATSHEET. Created by Pam Selle, inspired by work by Cat Farman. Used in GirlDevelopIt's 2013 JavaScript 
Course. Original cheat sheet ​here​. 

       

You might also like