JavaScript is a lightweight object oriented programming language.
Which is used to sevral website for scripting webpage.
It is interpreted full-fledge programming language.
That enable danamic intractivity on website when applied to html document.
To create intractive website like:-
(1) Client-side validation
(2) Server-side validation
(3) Popup
(4) Events and many more...
* Client-side
* Server-side
* Mobile development
* Software development
JavaScript is a weakly typed language (dynamically typed). JavaScript can be used for Client-side
developments
as well as Server-side developments. JavaScript is both an imperative and declarative type of language.
JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of
language elements like operators, control structures, and statements.
| Version | Name | Release Year | Features |
|---|---|---|---|
| ES1 | ECMAScript 1 | 1997 | Initial Release |
| ES2 | ECMAScript 2 | 1998 | Minor Editorial Changes |
| ES3 | ECMAScript 3 | 1999 | Add :
|
| ES4 | ECMAScript 4 | Abandoned due to conflicts | ... |
| ES5 | ECMAScript 5 | 2009 |
Added :-
|
| ES6 | ECMAScript 2015 | 2015 |
Added :-
|
| ES7 | ECMAScript 2016 | 2016 |
Added :-
|
| ES8 | ECMAScript 2017 | 2017 |
Added :-
|
| ES9 | ECMAScript 2018 | 2018 |
Added :-
|
| ES10 | ECMAScript 2019 | 2019 |
Added :-
|
| ES11 | ECMAScript 2020 | 2020 |
Added :-
|
| ES12 | ECMAScript 2021 | 2021 |
Added :-
|
| ES13 | ECMAScript 2022 | 2022 |
Added :-
|
| ES.Next | Dynamic name for upcoming versions |
European Computer Manufacturer's Association
ECMA is a organization to create a standard for technologies. It is provide rule, details and guideline.
The ECMAScript specification is a standardized specification of a scripting language developed by
Brendan
Eich of Netscape; initially named Mocha, then LiveScript, and finally JavaScript.
(1) Single line comment.
(2) Multiline comment.
The javascript program is a set of intruction / list of instructions also called statement.
* JavaScript is a dynamically typed language so the type of variables is decided at runtime. Four ways
to
define varriable??
a= "HTML"
var b = "CSS";
let c = "javascript";
const d = "JAVa";
Diffrence between let, var and const??
| Property | var | let | const |
|---|---|---|---|
| Scope | Function scoped | Block scoped | Block scoped |
| Redeclaration | Yes | No | No |
| Re-Assign | Yes | Yes | No |
| Hoisting | Hoisted at top | No Hoisted | No Hoisted |
| Origins | Pre ES2015 | ES2015(ES6) | ES2015(ES6) |
| Support | Supported in the old version of Browser | Not supported in the old version of the Browser | Not supported in the old version of the Browser |
There are majorly two types of languages.
Statically typed language :- Where each variable and expression type is already known at
compile
time. Once a variable is declared to be
of a certain data type, it cannot hold values of other data types.
Example: C, C++, Java.
Dynamically typed languages:-These languages can receive different data types over time. In this
type
of language, we don’t need to specify whether the value in the variable is an integer, string, or any
other
data type like float, double, etc. The JavaScript Engine automatically understands the data type. We can
re-assign any variable with any other value having another data type as given below.
Example: Ruby, Python, JavaScript
Datatype are two type :- (1). Primitive(predefined). (2). NonPrimitive(Reference)
| Primitive | Non-Primitive |
|---|---|
| Primitive Data types are predefined. | Non-Primitive data types are created by the programmer |
| Primitive Data types will have certain values. | Non-Primitive data types can be NULL. |
| Size depends on the type of data structure. | Size is not fixed |
| Examples are numbers and strings. | Examples are Array and Linked List. |
| It can start with a lowercase. | It can start with uppercase. |
JavaScript operators perform the operation between two or more operands.
JavaScript String Object is a sequence of characters. It contains zero or more characters within
single or
double quotes.
const name = "String Content";
const str = new String("career-inspire");
const str1 = new String("vijay dinanath chouhan");
const str2 = "vijay dinanath chouhan";
console.log(str1 == str2); output :- true
console.log(str1 === str2); output :- false
name.length
name.slice(start, end) (2),(2, 4) ,(-10),(-9,-6)
name.substring(start, end)
name.substr(start, length)
name.replace("a","@")
name.replaceAll("a","@")
name.toUpperCase()
name.toLowerCase()
name.concat(" ","string-2")
name.trim()
name.trimStart()
name.trimEnd()
name.charAt(positionIndex)
name.charCodeAt(positionIndex)
name.split(" ")
JavaScript Array is a single variable that is used to store elements of different data types. JavaScript
arrays are zero-indexed.
Two ways to declare an array.
(1). Array literal :- let arrayName = [value1, value2, ...];
(2). Using new keyword :- let arr = new Array();
Array.length
Array.toString()
Array.pop()
Array.push("val-last")
Array.shift()
Array.unshift("val-first")
Array.join("-")
Array.delete() :- delete array[0];
Array.concat(array2)
Array.flat() :- [[1,2],[3,4],[5,6]] ==> [...]
Array.splice(2, 0, "val1", "val2")
Array.slice(0,1)
Objects, in JavaScript, are the most important data type and form the building blocks for modern JavaScript.
The Javascript Math object is used to perform mathematical operations on numbers.
Methods
Math.abs()
Math.cbrt()
Math.ceil()
Math.exp()
Math.floor()
Math.log()
Math.log10()
Math.log1p()
Math.log2()
Math.max()
Math.min()
Math.pow()
Math.random()
Math.round()
Math.sqrt()
Math.abs(-4.7): 4.7
Math.ceil(4.4): 5
Math.floor(4.7): 4
Math.sin(90 * Math.PI / 180): 1
Math.min(0, 150, 30, 20, -8, -200): -200
Math.random(): 0.9578893866660307
Math.SQRT2: 1.4142135623730951
Math.SQRT1_2: 0.7071067811865476
Math.LN2: 0.6931471805599453
Math.E: 2.718281828459045
Math.PI: 3.141592653589793
Function :- One of the fundamental building blocks in JavaScript.
Function has a set of statements that performs a task.
Js function are used to perform the operation we can call the function many time.
Syntax :-
function functionName(parameters){* Function hoisting???
...peace of code...
}
square(5) // 25
function square(n) { return n * n; }
Function declaration
function person() { }
let person = person()
console.log(person) // Undefined
function person1(name) {
return name;
}
console.log(person1) // Aayush
let person1 = person1("Aayush")
Function Constructor:-
let person = new Person();
Creating the Constructor function
function Person(name, age) {
this.name = name;
this.age = age;
}
// Calling the function
let person = new Person("Vikah", 22);
console.log(person.name);
console.log(person.age);
Anonymous fuction??
var myfun = function () {
console.log("I am Anonymous function!");
};
myfun();
setTimeout(function () {
console.log("I am Anonymous function call after 2 second!");
}, 2000);
var myFun = () =>
{
console.log("I am Anonymous Arrow function!");
}
myFun();
Return type fuction??
IIFC type fuction?? (Immediately Invoked Function Expressions)
(function() {
console.log("Welcome to IIFE!");
})();