Variable Js
Variable Js
var myVariable = 5;
var _myVariable = 10;
var $myVariable = 15;
3 Case Sensitivity: JavaScript variable names
are case-sensitive, meaning myVariable and
MyVariable are treated as different variables.
var myVariable = 5;
var MyVariable = 10;
console.log(myVariable); // Outputs: 5
console.log(MyVariable); // Outputs: 10
myVar=5;
console.log(myVar); // Output: 5
var myVar; //----This declaraation is moved to top even before the
code execution—Hoisting
let x = 5;
x = 10; // This is valid
11 Initialization: It’s recommended to initialize
variables when declaring them to avoid
unexpected behavior due to undefined
values.
x = 5;
Data types
1 Primitive Data Types:primitive data types
are the fundamental building blocks used to
represent single values. Primitive data types are
directly stored in memory and are immutable,
meaning their values cannot be changed after
they are created.
◦ Number: Represents numeric values,
including integers and floating-point numbers.
◦ String: Represents textual data, enclosed in
single or double quotes.
◦ Boolean: Represents a logical value, true or
false
◦ Undefined: Represents a variable that has
been declared but has not been assigned a
value.
◦ Null: Represents an intentional absence of any
object value.
Type Conversion
Type coercion refers to the
automatic or implicit conversion of
values from one data type to
another. This process happens in the
background during operations
involving values of different types.
Types of Type Conversion
Implicit Conversion: This occurs
automatically when JavaScript
encounters an operation involving
different data types.
Explicit Conversion: This is when
you manually convert a value from
one type to another using functions
or methods.