Page 190 - Web_Application_v2.0_C12_Fb
P. 190
Allowed Characters: Variable names can include Letters (a-z, A-Z), Digits (0-9), dollar sign ($), underscore (_).
However, variable names cannot start with a digit.
For example:
var student_name = "Aisha"; // valid
var 1Place = "Winner"; // invalid, starts with a number
No Reserved Keywords: Variable names cannot be JavaScript reserved words. Reserved words (or
keywords) are special terms that have a predefined meaning in the language’s syntax. These words are
reserved for specific tasks and cannot be used as identifiers — such as variable names, function names, or
class names — to avoid conflicts with JavaScript’s built-in functionality.
Constants in Upper Case: Variables that hold constant values are often written in UPPERCASE letters,
with underscores to separate words.
For example:
const MAX_SCORE = 100;
const COUNTRY_NAME = "INDIA";
JavaScript Variable Scope
In JavaScript, variable scope determines where a variable can be accessed within your code. The two primary
types of scope are global scope and local scope.
Global Scope Variables: These variables are declared outside any function or block, giving them global scope.
This means they can be accessed from anywhere in the JavaScript code — including within functions, blocks,
and other parts of the program. They’re usually declared at the start of the script and remain accessible
Local Scope Variables: These variables are declared within a function or block and have local scope. These
variables are only accessible within the function or block where they are defined. Function parameters are
also considered local variables within the function. Local variables are not accessible from outside the
function in which they are declared.
JavaScript Literals
In JavaScript, literals are fixed values written directly into your code. Unlike variables, which can change
during a program's execution, literals represent constant, unchangeable values. They form the foundation of
JavaScript, allowing you to define different types of data — such as numbers, text, conditions, and collections
— essential for building programs. Some different types of literals are as follows:
Number literals represent integers or floating-point numbers.
String literals hold textual data.
Boolean literals represent the binary true/false logic.
Object and array literals provide structured data formats.
For example:
var language = "French"; // String literal
var score = 100; // Number literal (integer)
var price = 56.32; // Number literal (floating-point)
var marks = [12, 24, 36]; // Array literal
var isPassed = false; // Boolean literal
188 Touchpad Web Applications (Ver. 2.0)-XII

