Conditional Statements and Loops
Pop Up Box
1. var 2. let 3. Const
Example: var x= 5;
a. Local Scope b. Global scope
b. Variable declared outside a function becomes a global variable. Global variables have global scope. All scripts and functions on a web page can access it.
Variables are often declared without a value; this value can be something to be calculated or proved or can be user input. This is called undefined variable.
What are undeclared variables?
Undeclared variables occur when we try to access any variable that is not initialized or declared earlier using var or const keyword.
Example- const x= 2 //Allowed
const x= 3 //Not Allowed
let x= 2;
//// x can NOT be used here
a. Identifiers are names.
c.The rules for legal names are much the same in most programming languages.
e.Subsequent characters may be letters, digits, underscores, or dollar signs.
f.First character cannot be numbers.
Declaring a global variable:
Example: window.value= 50;
Now it can be declared inside any function and can be accessed from any function. The window object represents the browser's window.
What is Variable Typing?