JavaScript Basics
Explore core JavaScript fundamentals including primitive and reference data types like strings, numbers, booleans, objects, arrays, functions, and dates. Understand type checking with typeof and explicit type conversions. This lesson equips you with foundational knowledge needed to build front-end applications with plain JavaScript.
We'll cover the following...
Data types
JavaScript has three primitive datatypes–string, number, and boolean. There are five reference datatypes–Object, 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:
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 example will help us understand the use of the length attribute.