BASICS

DECLARATIONS

Declarations are foundational for any programming language. Declarations in JavaScript start with "let" or "const" and end with ";".
Variables in javaScript are typically declared in camelCase.

let, const, AND var

let is a mutable variable, use it if you expect the value to change in the program. Its scope is limited to the block of code it is declared in. Example below.

			
let myFirstVar = "Rico";
			

const is an immutable variable. It must be declared on one line. Its scope is block only. Use const to declare variables that should not change. Example below.

			
const neverStop = "Never Stop Not Stopping.";
				

var is the method used to declare a global variable is scope is the entire script. Example below:

			
var global = "This variable is global to the entire script.";
			

FIXME: add declarations, operators, datatypes, code blocks, syntax.

DATA TYPES

Type Name Python Equivalent Example Notes
String string let name = "Mia"; Can be declared with '' or "".
Number int, float let x = 5; intNr=1; decNR= 1.1; expNR=1.1e15; hexNR=f; 0b101=5;
BigInt N/A let bigNr =12578811788185484n Used for numbers between 2^53-1 and -(2^53-1). Cannot mix datatypes.
Boolean bool let mybool= false; or let mybool = true; true and false are lowercase in JavaScript.
Symbol N/A let compare = Symbol(5); FIXME: More research required to define these.
Undefined N/A let dog; output returns Undefined.
Null N/A let loggedIN = null; It means a variable has no value, but has been declared.

COMMENTS


//is a single-line comment in JavaScript.
				
/* is a multi-line comment in JavaScript*/

STRING LINE BREAKS

const blackDog = "Rico is my dog.\nHe is all black."
//linebreak

const  whiteDog = "Mia is my wife's dog.\n\n.She is all white."
// /n/n breaks lines and adds a blank space below the break.

Converting Data Types

Converting data types is a common workflow in all programming languages. JavaScript has an interesting nuance where 'String-Numbers' such as "4" can conduct math operations (*, -, /, and %) with Number data type such as 5. So "4" * 5 = 20 the Number in JavaScript! However, if "4" + 5 were used, it would concatenate them into the String "45"!

To add a String and a Number and avoid concatenation, the string must be converted to a number in the operation such that:


let myNewNum = 4;
let myStringNum = "4";
console.log( myNewNum + Number(myStringNum));

// this outputs 8

Boolean Conversions

Like in other languages an empty String or a Number == 0, when converted to a bool will be false. A populated string or any non-zero value will evaluate as true. Remember, in JavaScript 'true', and 'false' are lower case.

Unary Operators FIX ME ADD REST OF CONTENT FOR INCREMENTORS AND DECREMENTORS

"Incrementors" as I like to call them are expressed as ++. These operators ad