DAY-3
JAVASCRIPT
Data Types
Today, we’re going to focus on JavaScript data types and variables. Data is stored and given a name using variables so that it is easier to find them afterward. The type of data being stored is determined by data types. Let’s examine the various data types and variable types available in JavaScript.
Declaring Variables:
To declare a variable in JavaScript, we use the var
, let
, or const
keyword, followed by the variable name. For example:
var age;
let name;
const PI = 3.14;
Let and const have block scope, whereas the keyword var has global scope or function scope.
Assigning Values:
The assignment operator (=) is used to give a value to a variable. For example:
age = 25;
name = "update Gadh";
Data Types:
There are various built-in data types in JavaScript:
Number: Represents numerical values as a number. Let age be 25, for instance.Â
String: Represents textual information contained in quotation marks. Let the name be “John Doe” as an example.
Boolean: Represents either true or false. Let isActive, for instance, be true.
Array: An array is a representation of an organized group of values. Let numbers be [1, 2, 3, 4, 5].
Object: Represents a group of key-value pairs. For instance:
let person = {
name: "John Doe",
age: 25,
isActive: true
};
Dynamic Typing
The data type of a variable can be changed at any time because JavaScript is a dynamically typed language. For instance:
let age = 25;
age = "Twenty-Five"; // Valid, changing the data type
Typeof Operator:
We can use the typeof operator to identify a variable’s data type. For instance:
let name = "John Doe";
console.log(typeof name); // Output: "string"
These are the fundamental concepts of variables and data types in JavaScript. Practice declaring variables and assigning values of different data types to gain a better understanding.
Tomorrow, we will cover operators and expressions in JavaScript. Keep up the good work!
Read More :https://updategadh.com/javascript/30-days-of-javascript-day-3/
Â
Post Comment