JavaScript Cheatsheets or Basics Reference

The JavaScript language itself, as a format, is free, and the use of JavaScript in a website is not necessarily. JavaScript Cheatsheets contain useful code examples on a single page. … Find code for JS loops, variables, objects, data types, strings, events, and many.

Javascript is the most popular programming language in the world and that makes it a programmer’s great choice. Once you learned Javascript, it helps you developing great front-end as well as back-end software using different Javascript-based frameworks like jQuery, Node.JS, etc.

JavaScript Cheatsheets helps you create really beautiful and crazy fast websites. You can develop your website with a console-like look and feel and give your users the best Graphical User Experience.
The great thing about JavaScript Cheatsheets is that you will find tons of frameworks and Libraries already developed which can be used directly in your software development to reduce your time to market.

console.log()

console.log('Hi there!');
// Prints: Hi there!

Strings

let single = 'Wheres my project code?';
let double = "Wheres my project code?";

Numbers

let amount = 6;
let price = 4.99;

Booleans

let lateToWork = true;

Null

let x = null;

Arithmetic Operators

+ addition
- subtraction
* multiplication
/ division
% modulo


// Addition
5 + 5
// Subtraction
10 - 5
// Multiplication
5 * 10
// Division
10 / 5
// Modulo
10 % 5

String .length

let message = 'good night';
console.log(message.length);
// Prints: 10
 
console.log('howdy'.length);
// Prints: 5

Math.random()

console.log(Math.random());
// Prints: 0 - 0.9

Math.floor()

console.log(Math.floor(5.95)); 
// Prints: 5

Single Line Comments

// This line will denote a comment

Multi-line Comments

/*  
The below configuration must be 
changed before deployment. 
*/

Remainder / Modulo Operator

// calculates # of weeks in a year, rounds down to nearest integer
const weeksInYear = Math.floor(365/7);
 
// calcuates the number of days left over after 365 is divded by 7
const daysLeftOver = 365 % 7 ;
 
console.log("A year has " + weeksInYear + " weeks and " + daysLeftOver + " days");

Javascript Variables

// examples of variables
let name = "Mycodetips";
const found = false;
var age = 3;
console.log(name, found, age);
// Mycodetips, false, 3

const Keyword

const numberOfColumns = 4;
numberOfColumns = 8;
// TypeError: Assignment to constant variable.

let Keyword

let count; 
console.log(count); // Prints: undefined
count = 10;
console.log(count); // Prints: 10

Assignment Operators

+= addition assignment
-= subtraction assignment
*= multiplication assignment
/= division assignment
let number = 100;
 
// Both statements will add 10
number = number + 10;
number += 10;
 
console.log(number); 
// Prints: 120

String Concatenation

let service = 'credit card';
let month = 'May 30th'; 
let displayText = 'Your ' + service  + ' bill is due on ' +  month + '.';
 
console.log(displayText);
// Prints: Your credit card bill is due on May 30th.

Variables

const currency = '$';
let userIncome = 85000; 
 
console.log(currency + userIncome + ' is more than the average income.');
// Prints: $85000 is more than the average income.

Declaring Variables

var is used in pre-ES6 versions of JavaScript.
let is the preferred way to declare a variable when it can be reassigned.
const is the preferred way to declare a variable with a constant value.
var age;
let weight;
const numberOfFingers = 20;

Happy Coding on JavaScripting 🙂


Discover more from mycodetips

Subscribe to get the latest posts sent to your email.

Discover more from mycodetips

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top