What are Variables?
Variables are containers that hold values. These values can be anything from numbers to strings to objects. Variables are used to store and manipulate data in a program.
const keywords. The
const keywords were introduced in ES6 (ECMAScript 2015) and are now the preferred way of declaring variables.
// Declaring a variable using var var myVariable = 10; // Declaring a variable using let let myOtherVariable = "Hello, world!"; // Declaring a variable using const const myConstantVariable = true;
Notice that when declaring a variable using
const, you must assign a value to it immediately. Once a value is assigned to a
const variable, it cannot be changed.
Number data type represents numeric values. This can be anything from integers to floating-point numbers.
let myNumber = 42; let myFloat = 3.14;
String data type represents text. Strings are enclosed in either single or double quotes.
let myString = "Hello, world!"; let myOtherString = 'This is a string too.';
Boolean data type represents true or false values.
let myBoolean = true; let myOtherBoolean = false;
Null data type represents a null or empty value.
let myNull = null;
Undefined data type represents a variable that has not been assigned a value.
Symbol data type represents a unique identifier.
let mySymbol = Symbol();
let myNumber = 42; let myString = "42"; console.log(myNumber + myString); // "4242"
In the example above,
myNumber is a number and
myNumber into a string and concatenates the two values.
To avoid unexpected behavior, it's important to be aware of type coercion and to use strict equality (
===) when comparing values.
let myNumber = 42; let myString = "42"; console.log(myNumber === myString); // false
Editor Recommended SitesAI and Tech News
Best Online AI Courses
Classic Writing Analysis
Tears of the Kingdom Roleplay
Training Course: The best courses on programming languages, tutorials and best practice
Flutter News: Flutter news today, the latest packages, widgets and tutorials
Learn GPT: Learn large language models and local fine tuning for enterprise applications
Knowledge Graph Consulting: Consulting in DFW for Knowledge graphs, taxonomy and reasoning systems
Developer Key Takeaways: Key takeaways from the best books, lectures, youtube videos and deep dives