JavaScript Tutorial

JavaScript Data Types

string, number, boolean, undefined, null, object, bigint, and symbol. typeof reports the kind.

Eight kinds of value

Every value in JavaScript has a type. The seven primitives are string, number,boolean, undefined, null, bigint, andsymbol. Everything else is an object: plain objects, arrays, dates, and functions.

You do not declare the type when you write let name = "Mina". JavaScript infers it from the value. The same name can later hold a different type. That flexibility is convenient and is also a source of bugs — which is why typeof exists.

typeof

typeof value returns a string naming the kind. Use it when a value is not what you expected — a form field that is still a string, a missing property that is undefined, a function you thought was an object.

Example

console.log(typeof "Mina");
console.log(typeof 42);
console.log(typeof 3.14);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof { city: "Lisbon" });
console.log(typeof [1, 2, 3]);

Open /javascript/try with Try it in JavaScript. The console prints each type string.

string, number, boolean

A string is text in quotes: "Hello", 'Hello', or a backtick template. A number is an integer or a fraction: 7, 3.5,-2. A boolean is true or false — the result of a comparison, or a flag you set yourself.

These three are the everyday types. Most of the scripts in this tutorial are strings for labels, numbers for counts and prices, and booleans for decisions.

undefined and null

undefined means no value was assigned. A declared let with no initializer isundefined. A missing object property is undefined. A function with noreturn returns undefined.

null is a value you assign on purpose to mean “nothing here.” Empty a selection withactiveUser = null. Do not use undefined for that: let the language useundefined for missing, and use null for empty.

Example

let title;
console.log(title);
console.log(typeof title);

let activeUser = null;
console.log(activeUser);
console.log(typeof activeUser);

typeof null is "object". That is a long-standing language bug, not a rule you should rely on. To test for null, write value === null. Do not use typeof for that check.

object (and arrays, and functions)

An object is a collection of named values: { name: "Mina", age: 28 }. An array is an ordered list: [10, 20, 30]. Both have typeof equal to "object". A function is a callable object; typeof reports "function" so you can tell it apart.

Example

const person = { name: "Mina", city: "Lisbon" };
const scores = [10, 8, 9];
function greet() {
  return "hello";
}

console.log(typeof person);
console.log(typeof scores);
console.log(typeof greet);
console.log(Array.isArray(scores));
console.log(Array.isArray(person));

To tell an array from a plain object, use Array.isArray. Do not use typeof for that — both are "object".

bigint and symbol

bigint holds integers bigger than Number.MAX_SAFE_INTEGER. Write an suffix: 9007199254740993n. You cannot mix bigint and number in arithmetic without converting. Everyday pages almost never need bigint.

symbol is a unique identifier: Symbol("id"). Two symbols with the same description are still not equal. Libraries use them as collision-free keys. You can ignore symbols until a later API requires one.

Example

const huge = 9007199254740993n;
console.log(typeof huge);

const first = Symbol("id");
const second = Symbol("id");
console.log(typeof first);
console.log(first === second);

typeof cheat sheet

Valuetypeof
"Mina""string"
42"number"
true"boolean"
undefined"undefined"
null"object" (quirk)
{}"object"
[]"object"
function() {}"function"
10n"bigint"
Symbol("x")"symbol"

Types move around

JavaScript converts types when an operator asks for it. "5" * 2 becomes 10."5" + 2 becomes "52". Boolean("") is false. Prefer explicit conversion when the value comes from a form or from JSON: Number(text),String(n), Boolean(value).

Next: functions — a named block you call, with parameters in and a return value out.

FAQ: JavaScript Data Types

Common questions about this page.

What is the StudyGrid JavaScript tutorial?

The StudyGrid JavaScript tutorial is a full beginner track: variables, functions, arrays, if/else, the DOM, events, storage, and fetch. Each chapter has copy-and-run examples.

Should I run javascript data types examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn javascript data types in this JavaScript JavaScript lesson (JavaScript Data Types).

Is the JavaScript editor the same as Try Python?

No. Try JavaScript is a live page plus a console at /javascript/try. Try Python stays at /try. JavaScript lessons never open the Python editor.

Do I need to install anything to learn JavaScript?

No. Open a chapter, click Try it in JavaScript, and the page and console update in the browser.

Where should I start the JavaScript tutorial?

Start at JavaScript Intro, then Where To, Output, and Syntax. After variables and functions, continue to the DOM and events. Use Next at the bottom of each chapter.

Is the JavaScript tutorial free?

Yes. The JavaScript studio on StudyGrid (studygrid.in) is free: dashboard, chapters, and the live editor.