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

Javascript Cheat Sheet 2

This document provides an overview of JavaScript basics, including console output, arithmetic operators, comments, variables, loops, data types, logical and comparison operators. It explains how to use conditionals, while and for loops, and control flow with keywords like continue and break. The document serves as a foundational guide for beginners learning JavaScript programming.

Uploaded by

Jalal Nayan
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)
4 views

Javascript Cheat Sheet 2

This document provides an overview of JavaScript basics, including console output, arithmetic operators, comments, variables, loops, data types, logical and comparison operators. It explains how to use conditionals, while and for loops, and control flow with keywords like continue and break. The document serves as a foundational guide for beginners learning JavaScript programming.

Uploaded by

Jalal Nayan
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/ 1

JAVASCRIPT : BASICS I

console.log() Output data to the console Arithmetic Operators Everyday math operations

// Print any text or variable score = 4 + 3 // Addition


console.log(" 👋
Howdy!"); score = 4 - 3 // Subtraction
// Print inside single or double quotes score = 4 * 3 // Multiplication
console.log(' 👋
Howdy!'); score = 4 / 3 // Division
score = 4 % 3 // Modulus
score = 4 ** 3 // Exponent
Comments Used for documentation

// Single line comment Conditionals Control the order of code execution


console.log('Hi');
/* Multi-line comment if (num > 0) {
console.log("Hi"); */ console.log("number is positive");
} else if (num == 0) {
console.log("number is zero");
let Used for variables where value will change
} else {
let score = 0; console.log("number is negative");
score = 3; }
console.log(score); // Output: 3

While Loop Will run until condition is true


const Used for variables where the value is constant
let count = 0;
const userID = 161803; while (count < 5) {
console.log(userID); // Output: 161803 console.log(count);
count++;
} // Will print numbers from 0-4
Data Types The five most used data types

// Numbers
let year = 2024; For Loop Runs based on an iterator variable
// Strings
let user = "@MrBeast"; for (let i = 1; i <= 3; i++) {
// Boolean console.log("Beetlejuice!");
let hungry = true; }
// Null // Will print "Beetlejuice!" 3 times
let newHire = null;
// Undefined Continue Keyword skips an iteration in a loop
let startingDate = undefined;
for (let i = 0; i < 5; i++) {
if (i == 1) {
Logical Operators Evaluate two conditions continue;
}
a && b # true if both conditions are true
console.log(i);
a || b # true if one condition is true
} // Will print numbers 0-4 except 1
!a # true if the condition is false

Break Keyword that ends the loop iteration


Comparison Operators Compare two values
for (let i = 0; i < 5; i++) {
a === b // Strict equal
if (i == 3) {
a !== b // Strict not equal
break;
a < b // Less than
}
a <= b // Less than or equal to
console.log(i);
a > b // Greater than
}
a >= b // Greater than or equal to
// Will print numbers 0-2

Made with by

You might also like