0% found this document useful (0 votes)
32 views

Javascript Cheatsheet

Uploaded by

Beachboy Alekoh
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)
32 views

Javascript Cheatsheet

Uploaded by

Beachboy Alekoh
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/ 6

Firefox about:srcdoc

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

// Returns a number between 0 and 1


.
Math.random();

Math.random();
.
// Math is the built-in object

let amount = 6;
let price = 4.99;

.length
.length let message = 'good nite';
console.log(message.length);
// Prints: 9

console.log('howdy'.length);
// Prints: 5

1 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc

let lateToWork = true;


true false

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

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

// This line will denote a comment


//

let x = null;
null

let single = 'Wheres my bandit hat?';


let double = "Wheres my bandit hat?";
' "

2 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc

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

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

let baseUrl = 'localhost/taxwebapp


/country';

// 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");

3 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc

let number = 100;

+= // Both statements will add 10


-= number = number + 10;
*= number += 10;
/=

console.log(number);
// Prints: 120

let age = 7;

text // String concatenation


${expression} text 'Tommy is ' + age + ' years old.';

// String interpolation
`Tommy is ${age} years old.`;

const currency = '$';


let userIncome = 85000;

console.log(currency + userIncome + ' is


more than the average income.');
// Prints: $85000 is more than the average
income.

undefined var a;

undefined console.log(a);
// Prints: undefined

4 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc

// Examples of variables
let name = "Tammy";
const found = false;
var age = 3;
console.log(name, found, age);
// Prints: Tammy false 3

var age;
let weight;
var
let const numberOfFingers = 20;

const

let name = "Codecademy";


${expression}
console.log(`Hello, ${name}`);
' "
// Prints: Hello, Codecademy

console.log(`Billy is ${6+8} years old.`);


// Prints: Billy is 14 years old.

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

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

5 of 6 6/14/2023, 10:02 AM
Firefox about:srcdoc

let service = 'credit card';


+
let month = 'May 30th';
let displayText = 'Your ' + service + '
displayText bill is due on ' + month + '.';

console.log(displayText);
// Prints: Your credit card bill is due on
May 30th.

6 of 6 6/14/2023, 10:02 AM

You might also like