🌐
W3Schools
w3schools.com › js › js_variables.asp
JavaScript Variables
The let and const keywords were new to JavaScript in 2015. var x = 5; var y = 6; var z = x + y; Try it Yourself » ... JavaScript variables can hold 8 datatypes, but for now, just think of numbers and strings.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_variables.htm
JavaScript - Variables
When we define the variables without using any keyword, JavaScript considers them global variables and can use them anywhere inside the code. <html> <head> <title> Variables without var keyword </title> </head> <body> <script> name = "tutorialspoint"; // String type variable number = 10.25; // Number type variable document.write("name = " + name + ", number = " + number + "<br>"); </script> </body> </html>
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › variables-datatypes-javascript
Variables and Datatypes in JavaScript - GeeksforGeeks
It's block-scoped as well. ... JavaScript supports various datatypes, which can be broadly categorized into primitive and non-primitive types. Primitive datatypes represent single values and are immutable.
Published   February 24, 2018
🌐
W3Schools
w3schools.com › js › js_datatypes.asp
JavaScript Data Types
In the second example, since the first operand is a string, all operands are treated as strings. JavaScript has dynamic types. This means that the same variable can be used to hold different data types: let x; // Now x is undefined x = 5; // Now x is a Number x = "John"; // Now x is a String Try it Yourself » · A string (or a text string) is a series of ...
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Grammar_and_types
Grammar and types - JavaScript | MDN
Note: You might also see a third type of comment syntax at the start of some JavaScript files, which looks something like this: #!/usr/bin/env node. This is called hashbang comment syntax, and is a special comment used to specify the path to a particular JavaScript engine that should execute the script. See Hashbang comments for more details. JavaScript has three kinds of variable declarations. ... Declares a variable, optionally initializing it to a value.
🌐
Turing
frontend.turing.edu › lessons › module-1 › js-intro-to-data-types-variables.html
JS: Data Types & Variables - Front-End Engineering Curriculum - Turing School of Software and Design
On the first line, we see the variable declaration and initial assignment. Below, we see age = 31. Syntactically, there are many similarities. The main difference is, we do not use the keyword var. JavaScript recognizes a few different types of variables: var, let, and const.
🌐
DEV Community
dev.to › codenutt › everything-you-should-know-about-javascript-variables-p4f
Everything You Should Know About Javascript Variables - DEV Community
November 18, 2019 - Variables don't have types, but the values in them do. These types define intrinsic behavior of the values. - Kyle Simpson ... Note: All of these types except object are called "primitives".
🌐
Career Karma
careerkarma.com › blog › javascript › javascript variables
JavaScript Variables: The Complete Guide | Career Karma
December 1, 2023 - Variables can be used to store data in a program, such as strings, numbers, JSON objects, or boolean values. In JavaScript, there are three different variable types: var, let, and const.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Data_structures
JavaScript data types and data structures - JavaScript | MDN
Conceptually, undefined indicates the absence of a value, while null indicates the absence of an object (which could also make up an excuse for typeof null === "object"). The language usually defaults to undefined when something is devoid of a value: A return statement with no value (return;) implicitly returns undefined. Accessing a nonexistent object property (obj.iDontExist) returns undefined. A variable declaration without initialization (let x;) implicitly initializes the variable to undefined.
Find elsewhere
🌐
Medium
medium.com › @kaklotarrahul79 › understanding-javascript-variables-and-primitive-data-types-step-by-step-1cdf3bb46b48
Understanding JavaScript Variables and Primitive Data Types Step by Step | by Rahul Kaklotar | Medium
January 18, 2025 - Declare variables using var, let, and const. Try updating their values and observe the behavior. Create examples for each primitive data type and use typeof to check their types. Create an object and an array, then modify their properties or ...
Top answer
1 of 11
23

JavaScript variables are not typed.

JavaScript values are, though. The same variable can change (be assigned a new value), for example, from uninitialized to number to boolean to string (not that you'd want to do this!):

var x;       // undefined
x = 0;       // number
x = true;    // boolean
x = "hello"; // string
2 of 11
9

Javascript is dynamically typed, whereas other languages, C# and Java for example, are statically typed. This means that in Javascript variables can be reassigned to values of any type, and thus that you don't ever need to explicitly denote the type of variables or the return type of functions. If you saw code like this in a statically typed language

int x = 5;
x = "hello";

you would rightfully expect the compiler to start throwing up a big nasty TypeError. Javascript, on the other hand, will happily run this code even though the type changed.

var x = 5;
x = "hello";

Because variables can change types, the compiler can't know as much information about them. You should expect the tools for Javascript to be inferior to those of Java/C# as far as useful niceties like code completion go. Fewer mistakes will be caught at compile time and you will have to do more runtime debugging than you are probably used to.

That said, this also allows you to be more free with your variables and you can change types at will, which can often be convenient. You can write code like this if you want:

var x;               //typeof x === "undefined"
x = "Hello, world!"; //typeof x === "string"
x = 42;              //typeof x === "number"
x = false;           //typeof x === "boolean"
x = {};              //typeof x === "object"
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-variables-and-data-types-in-javascript
How to Use Variables and Data Types in JavaScript – Explained With Code Examples
August 19, 2024 - Variables having these type of data are called primitives because they hold simple values. The word primitive can be translated to mean non-complex. Primitive values are usually a single unit like 1, "cup", null, undefined, true, and so on. Let's briefly consider how these data types are used and what kind of operations you can perform with them. NUMBER: In JavaScript, all numbers are floating-point values.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-variables
JavaScript Variables - GeeksforGeeks
Variables in JavaScript can be declared using var, let, or const. JavaScript is dynamically typed, so variable types are determined at runtime without explicit type definitions.
Published   September 27, 2025
🌐
Full Stack Foundations
fullstackfoundations.com › blog › javascript variables and data types: complete beginner tutorial
JavaScript Variables and Data Types: Complete Beginner Tutorial
March 29, 2024 - And below, I have re-written the above code in TypeScript, which is a superset of JavaScript that we may look at (still deciding on this) much later in this series. When I say "superset", I'm referring to the fact that all JavaScript is valid TypeScript, but not all TypeScript is valid JavaScript (and must be "transpiled" into JavaScript to run). const variable1: number = 10; const variable2: string = "some value"; const variable3: boolean = false;
🌐
Learn JavaScript
learn-js.org › en › Variables_and_Types
Variables and Types - Learn JavaScript - Free Interactive JavaScript Tutorial
Boolean variables can only be equal to either true or false. There are two more advanced types in JavaScript. An array, and an object. We will get to them in more advanced tutorials. const myArray = []; // an array const myObject = {}; // an object · On top of that, there are two special types called undefined and null.
🌐
MindMajix
mindmajix.com › blog › javascript › types of javascript variables
▷ Types of JavaScript Variables | What is JavaScript
There are three types of keywords for a variable declaration in JS: var, let, and const. ... Var - It is an outdated keyword in Javascript. We cannot declare a variable without var in older browsers.
🌐
GUVI
guvi.in › blog › full stack development › variables and data types in javascript: a complete guide
Variables and Data Types in JavaScript: A Complete Guide
April 8, 2025 - They are objects that represent a list of items. ... 3. Function: In JavaScript, functions are first-class objects, meaning they can be stored in variables, passed as arguments to other functions, and returned from functions. ... Each data type in JavaScript has its unique features and use cases.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Variables
There are some lazy programmers who, instead of declaring new variables, tend to reuse existing ones. As a result, their variables are like boxes into which people throw different things without changing their stickers. What’s inside the box now? Who knows? We need to come closer and check. Such programmers save a little bit on variable declaration but lose ten times more on debugging. An extra variable is good, not evil. Modern JavaScript minifiers and browsers optimize code well enough, so it won’t create performance issues.
🌐
Mindsers Blog
mindsers.blog › en › post › learn-javascript-variables
Start Javascript: learn about variables - Mindsers Blog
October 3, 2022 - There are several types of variables in JavaScript. In the example of the 3 a, b and c variables we already talked about, each variable stocks a number.