Basics Notebook
JavaScript Basics
Welcome to the starting line. Here we cover the absolute essentials of JavaScript: declaring variables with var, let, and const, and understanding the various operators available in the language.
Variables
IN [ ]
// var is function scoped
console.log(x); // prints undefined or value
var x =5; IN [ ]
// let and const are block scoped
console.log(y); // error
let y =6;
const PI = 3.141592653589793; // unchangeableOperators
== equal to value
=== !== equal/notequal to value and equal type
IN [6]
let a = 5;
let b = "5";
console.log("a == b: " + (a == b) + " and a === b: " + (a === b)); IN [17]
// Arithmetic operators
let x = 5;
let z = x ** 2; // same as Math.pow(5,2)
console.log("x: " + x + " and z: " + z); IN [36]
// Bitwise XOR operator
let a = 5, b = 3;
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log("a: " + a + " and b: " + b); IN [1]
// isNaN(), Infinity (or -Infinity) are numbers
console.log(
" isNaN('10') = " + isNaN("10") +
"\n isNaN('John') = " + isNaN("John")+
"\n typeof NaN = " + typeof NaN+
"\n typeof Infinity = " + typeof Infinity+
"\n typeof -Infinity = " + typeof -Infinity+
"\n 5*Infinity = " + 5*Infinity+
"\n 5/0 = " + 5/0
)