JavaScript Variables
A JavaScript variable is the simple name of the storage location where data is stored. There are two types of variables in JavaScript which are listed below:
- Local variables: Declare a variable inside of a block or function.
- Global variables: Declare a variable outside function or with a window object.
Example: This example shows the use of JavaScript variables.
// Declare a variable and initialize it
// Global variable declaration
let Name = "Apple";
// Function definition
function MyFunction() {
// Local variable declaration
let num = 45;
// Display the value of Global variable
console.log(Name);
// Display the value of local variable
console.log(num);
}
// Function call
MyFunction();
Output:
Apple
45
JavaScript Syntax
JavaScript syntax refers to the rules and conventions dictating how code is structured and arranged within the JavaScript programming language. This includes statements, expressions, variables, functions, operators, and control flow constructs.
Syntax
console.log("Basic Print method in JavaScript");
JavaScript syntax refers to the set of rules that determines how JavaScript programs are constructed:
// Variable declaration
let c, d, e;
// Assign value to the variable
c = 5;
// Computer value of variables
d = c;
e = c / d;
JavaScript Values
There are two types of values defined in JavaScript Syntax:
- Fixed Values: These are known as the literals.
- Variable values: These are called variables
These are the features of JavaScript which have some predefined syntax:
Table of Content
- JavaScript Literals
- JavaScript Variables
- JavaScript Operators
- JavaScript Expressions
- JavaScript Keywords
- JavaScript Comments
- JavaScript Data Types
- JavaScript Functions
- JavaScript Identifiers