Skip to content

Javascript

Day 1

Lesson 1

console is an object, a collection of data and actions
Printing
.log() function that can print
console.log()
Commenting
// for single line comments
/* words inside this are ignored */ - for documentation purposes
Data Types
number
bigint
string
boolean
null
undefined
symbol
object
→ All data types have access to specific properties such as
length for the number of characters in a string
console.log(’hotdog’.length) = 6
Operators works on numbers and also to strings just like python, basically concatenation adding string to another string
Add +
Subtract -
Multiply *
Divide /
Remainder %
dot operators, accesses the functions/methods innate for that data typecon
Methods
can be called with
a period (dot operator)
name of the method
opening and closing parentheses
e.g → ‘example string’.methodName()
Basic examples for string
startsWith()
toUppercase()
trim() → removes whitespace
Built-in objects (libraries for python)
examples
Math.random() → gives random number 0 to 1 (decimal), can be multiplied to any whole number
Math.floor() → rounds the number to nearest whole number
Math.ceil() → gives nearest integer
Number.isInteger()

DAY 2

Variables
variables in JS cannot start with numbers
follow camel casing, small letter for first word
e.g. var favoriteFood = ‘pizza’
can be declared without values and be defaulted to contain ‘undefined’
var meal;
console.log(meal) \\outputs undefined
meal = ‘hotdog’
console.log(meal) \\outputs hotdog

Variable kinds
let - means can be assigned/re-assigned with different values
const - cannot be reassigned with a new value

Mathematical Operators with Variables
Basic calculate plus assign commands works
+=, -=, /=, *= → can be used using javascript and for let variables
Increment and Decrement operators
a++; or b—; works and will deduct or add 1 value to variables
String manipulation with variables
Concatenation
let favoriteAnimal = 'Dog';
console.log('My favorite animal: '+ favoriteAnimal);
String Interpolation
let myName = 'Ernest';
let myCity = 'Caloocan City';
console.log( `My name is ${myName}. My favorite city is ${myCity}`);
the key is to use caret to indicate that the thing to be printed is a template.

typeOF Operator
the equivalent of type() in python
let newVariable = 'Playing around with typeof.';
console.log(typeof newVariable);

Kelvin Weather Project ✅

Dog Years Project ✅

JS Versions: ES6 and Before


Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.