Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

Data Types and Keywords in JavaScript — Complete Guide | Tutorials Logic

JavaScript Data Types

JavaScript is a dynamic or loosely typed language, means we don't need to specify type of the variable because it is dynamically specified by JavaScript engine based on the type of input. We just need to use var or let keyword to create variable. There are basically two types of data type in JavaScript, which are given below-

Primitive Data Types:- There are besically five types of primitive data type in JavaScript, which are given below-

Data TypesDescription
StringIt represents any string (example "hello").
NumberIt represents any numeric value (example 777).
BooleanIt represents boolean value (example true or false).
UndefinedIt represents undefined value.
NullIt represents null value.

Non-primitive or Reference Data Types There are besically two types of non-primitive data type in JavaScript, which are given below-

Data TypesDescription
ArrayIt represents multiple values of same or different data types in a single variable.
ObjectIt represents instance by which we can access members.

JavaScript Keywords

JavaScript keywords are reserved words, which we cannot use to name the variables or functions. There are total of 63 keywords which JavaSscript provides to the programmers.

Keywords
abstractargumentsbooleanbreak
bytecasecatchchar
constcontinueclass*debugger
defaultdeletedodouble
elseevalenum*export*
extends*falsefinalfinally
floatforfunctiongoto
ifimplementsininstanceof
intinterfaceimport*let
longnativenewnull
packageprivateprotectedpublic
returnshortstaticswitch
synchronizedsuper*thisthrow
throwstransienttruetry
typeofvarvoidvolatile
whilewithyield-

Keywords, which are marked with * symbols are the new keywords in ECMAScript 5 and 6.

Type Checking with typeof and instanceof

Use typeof to check primitive types and instanceof to check object types.

Type Checking
// typeof - returns a string
console.log(typeof 42);           // "number"
console.log(typeof 'hello');      // "string"
console.log(typeof true);         // "boolean"
console.log(typeof undefined);    // "undefined"
console.log(typeof null);         // "object" (historical bug in JS!)
console.log(typeof {});           // "object"
console.log(typeof []);           // "object"
console.log(typeof function(){}); // "function"
console.log(typeof Symbol());     // "symbol"
console.log(typeof 42n);          // "bigint"

// instanceof - checks prototype chain
console.log([] instanceof Array);   // true
console.log({} instanceof Object);  // true
console.log([] instanceof Object);  // true (arrays are objects)

// Best way to check for array
console.log(Array.isArray([]));     // true
console.log(Array.isArray({}));     // false

// Null check
const val = null;
console.log(val === null);          // true (use strict equality)

ES6+ New Data Types - Symbol and BigInt

Symbol & BigInt
// Symbol - unique, immutable identifier (ES6)
const id1 = Symbol('id');
const id2 = Symbol('id');
console.log(id1 === id2); // false - every Symbol is unique

// Useful as unique object keys
const USER_ID = Symbol('userId');
const user = { [USER_ID]: 123, name: 'Alice' };
console.log(user[USER_ID]); // 123

// BigInt - integers larger than Number.MAX_SAFE_INTEGER (ES2020)
const bigNum = 9007199254740991n; // note the 'n' suffix
const bigger = bigNum + 1n;
console.log(bigger); // 9007199254740992n

// Cannot mix BigInt with regular numbers
// console.log(bigNum + 1); // TypeError
console.log(Number(bigNum) + 1); // convert first

// Practical: cryptography, database IDs, financial calculations
const MAX_SAFE = Number.MAX_SAFE_INTEGER;
console.log(MAX_SAFE + 1 === MAX_SAFE + 2); // true (precision lost!)
const bigSafe = BigInt(MAX_SAFE);
console.log(bigSafe + 1n === bigSafe + 2n);  // false (correct)
Key Takeaways
  • JavaScript has 8 data types: string, number, boolean, undefined, null, object, symbol, and bigint.
  • typeof null returns "object" - this is a known historical bug in JavaScript.
  • Use Array.isArray() to check for arrays, not typeof (which returns "object" for arrays).
  • Symbol creates a guaranteed unique value - useful for private object keys and avoiding naming collisions.
  • BigInt handles integers beyond Number.MAX_SAFE_INTEGER (2^53 - 1) without precision loss.
  • Reserved keywords cannot be used as variable names - they have special meaning in the language.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.