JS-2-2-Data Types
JS-2-2-Data Types
Here’s how the data types you've listed can be categorized in JavaScript:
2. Objects: Used for storing multiple related values and properties in a single
variable,
with key-value pairs inside curly braces {}.
Example: person stores information about a person with firstName and lastName.
Typeof Operator:
----------------
In JavaScript, typeof is an operator used to determine the type of a given variable
or expression.
It returns a string that represents the type of the operand.
Important Note:
--------------------
typeof returns "object" for arrays and null, so checking for arrays or null
requires additional logic.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript</title>
</head>
<body>
<h1>JavaScript typeof Operator</h1>
<h2>To See Console Output, Press F12 Key</h2>
<script>
// Number type
let num = 42;
console.log("Type of num:", typeof num); // "number"
// String type
let str = "Hello, World!";
console.log("Type of str:", typeof str); // "string"
// Boolean type
let isTrue = true;
console.log("Type of isTrue:", typeof isTrue); // "boolean"
// Object type
let obj = { name: "John" };
console.log("Type of obj:", typeof obj); // "object"
// Function type
let func = function() {};
console.log("Type of func:", typeof func); // "function"
// Undefined type
let undefinedVar;
console.log("Type of undefinedVar:", typeof undefinedVar); // "undefined"