Variables
Variables are the containers for storing information or a data. In Javascript , it can be declared in three ways:
1.var 2.let 3.count
1.var keyword – function scope or global scope. var variables can be re-declared and updated
var x=10
{
var y=20
}
console.log(y)
//output: 20
2. let keyword-block scope. let is only available for use within that block.
{
let x=20
console.log(x)
}
//output:20
3.const keyword – block scope. const cannot be updated or re-declared.
function myscript() {
const a = 30;
a = 40; // TypeError: Assignment to constant variable
}
myscript();
Operators
Javascript operators are used to perform operations on values and variables in different types of mathematical and logical computations.
Examples:
Assignment Operator : = assigns values between the variables
Addition Operator : + adds values between the variables
Multiplication Operator : * multiplies values between the variables
Comparison Operator : > compares values between the variables
Functions
In JavaScript, function is defined with the function keyword, followed by a name, followed by parentheses () designed to perform a particular tasks. The parentheses may include parameter names separated by commas like (a,b…)
Parameters refers to the variables or placeholder that you define when declaring a function. It serves as a inputs to the function and allows to pass data into a function.
function area(l,b)
{
result=l*b
console.log(result)
}
area(10,5)
//output:50