JavaScript Basics

Let’s learn the basics of JS data types.

Data types

JavaScript has three primitive datatypesstring, number, and boolean. There are five reference datatypesObject, Array, Function, Date, and RegExp. Arrays, functions, dates, and regular expressions are special types of objects, but conceptually, dates and regular expressions are primitive data values and happen to be implemented in the form of wrapper objects.

Below, we have an example of JS data types:

Press + to interact
let string = "Johnson"; // String
let number = 16; // Number
let bool = true; // Boolean
let object = {firstName:"John", lastName:"Doe"}; // Object
let array = ['Jim', 'Shawna']; // Array
function func() { return (5 * 19); } // Function
let date = new Date() // Date
console.log("String is: " + string)
console.log("Number is: " + number)
console.log("Object is: " + object.firstName + " " + object.lastName)
console.log("Array is: " + array)
console.log("Function is: " + func())
console.log("Date is: " + date.toUTCString())

String data

A string is a sequence of Unicode characters. String literals, like "Hello world!", 'A3F0', or the empty string "" are enclosed in single or double quotes. Two string expressions can be concatenated with the + operator and checked for equality with the triple equality operator.

The number of characters in a string can be obtained by applying the length attribute to a string. The following ...