i
Introduction Of JavaScript
Setup For JavaScript
Client-side and Server-side JavaScript
JavaScript Equivalents
JavaScript Syntax
JavaScript Variables
JavaScript Expressions
JavaScript Comments
JavaScript Identifiers
JavaScript Case Sensitive
JavaScript Function Definition
JavaScript Function Expressions
JavaScript Parameters and Arguments
JavaScript Function Invocation
JavaScript Self-invoking Functions
JavaScript Objects Definitions
JavaScript Object Properties
JavaScript Object Methods
JavaScript Object Constructors
JavaScript Object Prototypes
JavaScript Object ES5 standard
Strings Definition
Backslash escape character
Strings as Objects
String Methods
indexOf() and lastIndexOf():
search()
slice()
substring()
substr()
replace()
toUpperCase()
toLowerCase()
concat()
trim()
charAt()
charCodeAt()
split()
endsWith()
fromCharCode()
includes()
repeat()
startsWith()
valueOf()
Creating an Array
Array elements
Array Properties and Methods
Changing Elements of an array
Compare function of Array
Addition vs. Concatenation
Properties and Methods
JavaScript this Function
JavaScript let Function
Reserved Words
Removed reserved words
JavaScript Properties, Methods, and Objects
Java Properties and Objects
HTML and Window Properties, Objects and Event Handlers
Comparison operators
Logical Operator
Comparing different data types
Conditional Statements
else statement
switch statement
default statement
JavaScript Loops
JavaScript break statement
Function Expressions:
Functions can also be defined using expressions in JavaScript. This can be stored in a variable.
Example:
Consider an example of adding two numbers.
var sum = function (x, y) { return x + y };
This function is an example of an anonymous function since it does not have a name. If a function is stored in a variable, then it does not need a name. That function can be invoked using the variable name.
Function() constructor:
JavaScript has a built-in constructor, Function(), for defining functions.
var sum = new Function(“x”, “y”, “ return x + y”);
This is same as writing,
var sum = function (x, y) { return x + y };
In general, use of the built-in constructor, Function(), is not recommended.
Local variables:
The variables that are declared within a function are local variables, which are local to the function. They can be accessed only from within the function and cannot be accessed from outside the function.
Example:
function sum (x, y) {
var sum;
sum = x + y;
return sum; // returns the value of x + y
}
console.log(sum); // will print undefined because sum is declared and defined within the function and cannot be accessed from outside.
Used as variables:
It is not necessary that the return value of a function must be stored in a variable and then used. Functions can be used directly as well without storing the return value.
Example:
function sum (x, y) {
return x + y;
}
var output = “The sum of variables is 10 and 9 is” + sum(10, 9);
Function Hoisting:
Hoisting applies to both variables and functions in JavaScript. This allows to use a function even before it is defined/declared.
Example:
sum(x, y);
function sum (x, y) {
return x + y;
}
In the above example, the function sum is called first and then it is declared. However, because of hoisting, the function declaration moves to the top and hence when the sum function is called, it is executed as expected and does not throw an undefined error.
Don't miss out!