Tutorials JavaScript Tutorial

Data Types — Complete Guide

Data Types — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of JavaScript Tutorial on Toolliyo Academy.

On this page

JavaScript Tutorial · Lesson 5 of 100

Data Types

BasicsObjects & dataAsync & DOMAdvancedToolsProjects

Beginner · 1 — Learn by example · ~6 min · JS Tutorial — Basics

What is this?

Every value in JavaScript has a type: string (text), number, boolean (true/false), undefined, null, object, and more. typeof tells you what type a value is.

Why should you care?

Adding "5" + "3" gives "53" (string concat). Adding 5 + 3 gives 8 (math). Knowing types prevents silent bugs.

See it live — copy this example

Paste into an HTML file or the browser console (F12). Use Run below when the live editor is available.

console.log(typeof "hello");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof undefined);
let person = { name: "Amit", age: 22 };
console.log(typeof person);

Run Example »

Edit the code below and click Run to see the result in Toolliyo’s live editor.

Code
Result

What happened?

  • Strings use quotes.
  • Numbers have no quotes.
  • typeof returns a string naming the type.
  • Objects hold grouped data — person is an object.

Practice next

  1. Run each typeof line in the console.
  2. Try typeof null and note the quirk.
  3. Create let x; without assigning and check typeof x.
  4. Add typeof for a function: typeof function(){}.
  5. Create a bigint with 100n and log typeof 100n.

Remember

typeof shows the type Use quotes for strings, not for numbers Objects group related data

ScriptVerse API validation

A form handler checks typeof age === "number" before saving a profile — strings from inputs would break math otherwise.

Outcome: Type checks at boundaries catch bad data before it reaches the database.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
What are the different data types in JavaScript?
Short answer: Primitive types: string, number, boolean, null, undefined, symbol, bigint Reference types: object, array, function Example code let name = "Sandeep"; let obj = { age: 30 }; Real-world example (Sho…
Mid PDF Detailed
What are the three types of CSS selectors?
Short answer: Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags. p { color: green; } Element selector: Targets HTML tags…
Junior PDF Detailed
What is the difference between inline-block and block?
Short answer: block elements take full width and start on a new line. inline-block behaves like inline (stays in the same line) but allows setting width, height, margin, and padding. Example code .block { display: block;…
Mid PDF Detailed
Explain the difference between HTML4 and HTML5.
Short answer: HTML5 is the modern evolution of HTML4, introducing better structure, multimedia support, and APIs. Explain a bit more Follow me on LinkedIn: HTML4 mainly focused on document markup, while HTML5 focuses on…
Mid PDF Detailed
Class selector: Targets elements with a class.?
Short answer: .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow; } .highlight { background: yellow…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

JavaScript Tutorial
Course syllabus

JavaScript Tutorial

Tutorial — Basics
Control Flow & Functions
Objects & Collections
Strings, Dates & RegEx
Async JavaScript
HTML DOM & Web APIs
Advanced
Performance & Security
Testing & Tooling
Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details