JavaScript Basics

JavaScript Variables

Data Types in JavaScript

A value in JavaScript is always of a certain type. There are 8 major datatypes including strings and numbers. We can put any type of dataset in a variable, for example it could be a string then change to a number later on. Programming languages that allow such things, such as JavaScript, are called “dynamically typed”, meaning that there exist data types, but variables are not bound to any of them.

let message = 'hello';
message = 123456;

Numbers and Arithmetic

Handling text — strings in JavaScript

In JavaScript, primitive values, like "Java is not JavaScript" can have properties or methods, as the language treats all values as objects when executing.

An exhaustive list of string methods and properties can be found here

Additional Data Types

In addition to text strings and numbers there are 6 more major data types to be found in JavaScript.

JavaScript Functions

Conditionals Operators in JavaScript

Logical Operators

There are three logical operators in JavaScript. They can be applied to any value of any type (not just boolean) and can return a result of any type.

JavaScript Best Practices

Do not create Number objects. It slows down execution speed. The new keyword complicates the code. This can produce some unexpected results

wrap your code block with curly braces {} every time you use an if statement, even if there is only one statement to execute and it is not necessary. Doing so improves readability.

Writing code in JavaScript