JavaScript by shudhakar sharma
JavaScript by shudhakar sharma
=========================
-> JavaScript is light weight JIT [ just-in-time] complied and interpreted
programming Languages.
-> Interpreted allows to translate line by line of program.
-> Compiler allows to translate all lines simultaneously at the same time.
-> There are 2 types of compiling techniques:
a) JIT [ Just-in-time]
b) AOT [ Ahead-of-Time]
-> JIT is a mechanism where the programs loaded into browser and complied in
browser.
-> AOT is a mechanism where the program is complied and translated at application
level. It is
faster and improves performance of application.
End video no 35
-----------------------------------------------------------------------------------
-------------------------------
Integrating JavaScript into HTML page:
=================================
-> You can integrate JavaScript function into HTML page using 3 techniques
1. Inline
2. Embedded
3. External File
1. Inline Technique:
-> In allows developer to write JavaScript function directly inside element
-> It is faster but you can't reuse.
Syntax:
<button onclick="window.print()"> Print </button>
2. Embedded
-In this technique developer can keep all JavaScript function in a <script>
container.
- So that you can access and use from various location in page.
- You can embed in <head> or <body> sections.
Syntax:
<script>
faction PrintPage()
{
window.print();
}
</script>
Syntax:
<script type ="text/JavaScript">
</script>
Syntax:
<script type="module">
</script>
- JavaScript is not a strictly typed language. Hence you have to turn ON strict
mode manually.
- Strict mode allows to reduce code in-consistency.
- You can turn ON strict mode by using the following command.
"use strict";
Syntax:
<script type="text/javascript">
<"use strict"; => Invalid : x is not define
x=10;
document.write("x=" + x): => It is valid if you remove strict
mode
</script>
- You can target JavaScript functions to Legacy Browsers by enclosing the script in
HTML comments.
Syntax:
<script type="text/javascript">
"use strict";
<!--
function name() {
--!>
</script>
External File:
===========
- JavaScript functions can be defined in separate file with extension ".js"
- So that you can reuse the function across pages.
- Using an external file will always increase the number of requests and also load
time.
Ex:
1. Go to "scr" folder
2. Add a new folder "scripts"
3. Add a new file by name "print.js"
"use strict";
function PrintPage()
{
window.print();
}
<body>
<button onclick="PrintPage()"> Print</button>
</body>
- You can minify the JavaScript code and use minified code for production.
Drawback of JavaScript
====================
-> It is not a strongly typed language.
-> Validating data type requires explicit functions.
Note: The alternative for JavaScript that modern web developers use is
"TypeScript".
TypeScript is not replacement for JavaScript, It is a just an alternative.
End videos No 36
=======================
-----------------------------------------------------------------------------------
-------------------------------
Q. 1. How JavaScript refers HTML elements ?
Ans: JavaScript can refer HTML elements using DOM Hierarchy.
Syntax:
window.document.images[]
window.document.forms[].elements[]
- It is the fastest technique implemented for rendering dynamic elements.
- It is the native method for JavaScript to refer elements.
- However changing the position of element in page requires the change in index
number every time.
- "id" is a reference used by CSS, where it can be common for multiple elements.
- Hence ID is also having issues in manipulating element.
Syntax:
<img id="pic">
document.getElementById("pic").src="../public/image/kids.jpg";
- It can use all CSS selectors like, primary, rational, structural, attribute ect..
<img>
document.querySelector("img").src="path";
<input type="button" class="btn-login">
document.querySelector(".btn-login").value="Login";
1. alert() method:
- Alert will display a message box with some raw text.
- It can't have formatted text.
- It will not allow user to cancel.
- User have to confirm with OK and continue.
Syntax:
alert("you message");
alert("line-1 \n line-2);
alert(expression);
2. Confirm()
- It is similar to alert() but it allows to cancel.
- It returns a Boolean result
true on OK click
false on Cancel click
Syntax:
confirm ("your message"); true = OK, false = Cancel
3.document.write()
Syntax:
document.write("message | markup | expression");
Note: You can't use \n, you have define using <br>
4. innerText
- It is used to render output in any container element.
<p> <div> <span> <h2> <td> <dd> <header> ect..
5. InnerHTML
- it is similar to innerText but it allows all formats
- You can render markup using innerHTML
Syntax:
document.querySelector("p").innerText="deleted";
document.querySelector("div").innerHTMl="<b> deleted.</b>";
6. outerHTML
- It is similar to innerHTML, but will replace the existing markup with new markup.
Syntax:
document.querySelector("p").outerHTML="<h2> Wellcom</h2>";
End videos no 37
===================================================================================
=======
7. Console methods
- Console is a developer CLI [command line interface]
- It is provided with browser developer tools. [inspect]
- Developer can log all message as output in console.
- The various contextual console method are:
console.log()
console.error()
console.warn()
console.debug()
console.info() ect..
Syntax:
console.log("string | expression");
-----------------------------------------------------------------------------------
--------
JavaScript input Techniques
===========================
- User input can be form
a) Query String
b) Prompt()
c) From input Elements
1. Query String :
Note: "location.search" return complete query string, you have to use string
methods to extract only the value.
2. Prompt
- JavaScript "prompt()" method provides a popup that allows input from browser
windows.
- It is an input box to input value into page.
- Prompt method returns following
Syntax:
prompt("your message", "defualt_value_Optional");
-----------------------------------------------------------------------------------
-------
Form input Elements
=======================
- You can accept input from the element and render in UI.
- form element keep the content in the reference of "value".
End video no 38
=================================================================
JavaScript Language
===================
1. Variables
2. Data Types
3. Operators
4. Statements
5. Functions
1. Variables
---------
-> Variables are storage locations in memory, where you can store a value and use
it as a part of any expression.
Ex:
<script>
document.write("Hello" + prompt("Enter your Name") + "<br>);
document.write("Hi" + prompt("Enter your Name") + "Wel come to JavaScript");
</script>
<script>
username = prompt("Enter you Name")
document.write("Hello.. " + username + "<br>");
document.write("Hi " + username + " Wel come to JavaScript..");
</script>
Syntax:
<script>
x =10;
document.write("x" +x); => valid
</script>
Syntax:
<script>
"use strict";
x =10; invalid x is not defined
document.write("x" +x); => valid
</script>
-> JavaScript variables are declared by using 3 keywords
1. var
2. let
3. const
. var :
- It define a function scope variable.
- You can declare in any block of a function and can access from any another block
inside function.
- It allows declaring, assignment and initialization.
- It allows shadowing.
- Shadowing is the process of re-declaring or re-intitializing same name
identifier within the scope.
{
var x =10;
var x = 20; => variable shadowing
}
- It allow hoisting
- It is the process of declaring and using a variable form any location. There is
no order dependency. you can use and declare later in function.
<script>
"use strict";
x =10;
document.write("x"+x);
var x; => hoisting. note: we can only declare not initialized.
</script>
let :
- It define block scope variable.
- It is accessible within the specified block and to it's inner blocks
[ this mechanism is known as closure ]
const :
- It define block scope variable
- It supports only initialization.
- It not supports declaring, assignment.
- It not support shadowing and hoisting.
End Video no : 39
=================================================================
Variables Global Scope
======================
-Global scope defines the accessibility of variables across multiple functions.
- Declaring or initializing variables outside function makes as Global.
- you can configure a global variable inside function using "windwod" object of
JavaScripte.
window.varName = value;
Syntax:
<script>
var x = 10;
function f1() {
document.write("f1 x" +x + "<br>");
}
function.f2(){
document.write("f2 x=" +x);
}
f1();
f2();
</script>
---------------------------------------------------------------
Variable Naming
- Name must start with an alphabet.
- It can be alpha numeric with "_".
- You can start name with "_" . But is not recommended.
-ECMA doesn't recommended to using special chars.
-Name mac length can be upto 255.
- Never using keywords as variables.
EX:
var for;
var is: => Invalid
var while;
-Variable name must speak what it is.
- Always use camel case.
Ex:
var userName;
----------------------------------------------------------------
JavaScript Data Types
=====================
- In computer programming data type defines the data structure.
- It is about the type of behaviour of data in memory.
- JavaScript is not a strongly typed language.
- Hence there is not data type restriction for data in memory.
- JavaScript is implicitly type language. The data type changes according to the
values type.
Number Types:
=============
- A Number for JavaScript can be any one of the following.
signed integer -5
unsigned integer 5
float point 34.32
double 233.23
decimal 3242.32 [ 29 decimal places]
exponent 2e3 [2 x 10^3] = 2000
hexa 000fx45
octa 0o578
binary 0b1010
Syntax:
var x = 9988776543; // it is not safe
var x = 9988776543n; // it is safe [Bigint]
Syntax:
var age = parseInt(prompt("Enter Age"));
document.write ("you will be " + (age+1) +"next years"));
- You can verify the input type number or not by using JavaScript method "isNaN()"
- It is a Boolean method that return true if input value is not a number.
FAQ: How to verify input value number or not using regular Expression ?
Ans: By using pattern and javascript "match();
Eng Vides no 40
=================================================================
JavaScript String Types
=======================:
- String is a literal with group of characters enclosed in
a) double quotes ""
b) single quotes ''
c) back ticks ``
- Single and duble quotes are used to toggle outer and inner string
Syntax:
var link = "<href='home.html'>Home</a>";
var link = '<href="home.html">Home</a>';
- Binding dynamic value to a string requires lot of concat techniques using "+"
operator.
Syntax:
"string" + dynamicValue+"string"
- E5+ version of javascript introduced a data binding expression "${}", which you
can embed in a string with backticks only
Ex:
'string${dynamicvalue} string'
- String can not print few characters, to print the non-printable character you
have to use the escape sequence character "\".
Syntax:
let path = "d:\images"; => d:images
let path = "d:\\images"; => d:\images
Syntax:
var str = "welcome";
document.write(str.bole().italics().fontsize(4).fontcolor ('green'));
Event:
onblur : specifies actions to perform when elements lost focus.
onkeyup: specifies actions to perform when a key is related[every character].
Note: You can't apply font and style on RC data element using string methods.
Syntax:
var str = "44556600334";
str.startsWith("4455"); true;
str.endsWith("4455"); false;
str.endsWith("88") true;
End videos no : 41
-----------------------------------------------------------------
6. indexOf() : It return the index number of character in specified string. If
character not found the it returns "-1".
It returns the first occurrence of value index.
Syntax:
var str = "welcome";
str.indexOf("e"); // return 1 ;
str.indexOf("a"); // return -1;
str.lastIndexOf("e"); // 6
Syntax:
str.substr(startIndex, howManyChars);
str.substr(6,3); from 6 it can read 3 chars
11. split() : It can split the string into an array by using specified delimiter.
Syntax:
var details = "john-23, david-25, sam-31";
details.split(','); // [john-23, david-25, sam-31]
index -> 0 1 2
Ex:
<script>
var contacts = "john-8242423423 , david-23424234";
var [john, david] = contacts.split(",");
document.write(john + "<br>");
document.write(david);
</script>
Syntax:
var str = "welcome";
var result = str.trim(); // "welcome"
Ex:
script>
var otp = prompt("Enter OTP");
if (otp.trim() == "444") {
document.write("success");
} else {
document.write("Indalid OTP");
}
</script>
13. match() : It is used to compare your string with a regular expression and
return if string is according to given expression.
End Videos no 42
=================================================================
Boolean:
=======
- Boolean are used in decision making.
- Boolean types in JavaScript can handle the keywords "true & false".
- Boolean condition in JavaScript can manage using "1 and 0".
true = 1;
false = 0;
Undefined:
==========
-It refers to a memory where value is not defined.
- You can use "undefined" keyword to verify value in memory.
Syntax:
var x;
document.write("x:" +x) // x = undefined
- You can verify value in reference using simple decision making statement.
if(x){} // x is define or not
Null
====
- Null is a type configured for memory reference when value is not provided during
runtime.
- It is verified by using "null" keyword.
Symbol
======
- It is used to configure a hidden key for object.
- The hidden keys are ignored over iterations. But they are accessible
individually.
- Symbol is a new data type of JavaScript for developers from version ES6.
---------------------------------------------------------------
ARRAYS
---------------------------------------------------------------
- Arrays are introduced into computer programming to reduce overhead and
complexity.
- Arrays can reduce overhead by storing values in sequential order.
- Arrays reduce complexity by storing multiple values under the reference of single
name.
- Arrays can store various type of values.
- Arrays size can change dynamically.
Note: Some of the software programming technologies can't allocate different types
of memory in sequential order and can't change the size dynamically. Hence they
restrict array for similar types of values.
- JavaScript array can store various types and can change the size dynamically.
- Array refers to a type of arrangement, where elements are arranged sequentially
but can be accessed in random.
ex:
keyboard is having an arrays of keys.
Declaring Array:
- JavaScript array is declared by using var, let or const keyword.
- It used a reference name for storing values.
Syntax:
var products;
var categories;
var sales;
a) []
b) array()
var products;
product = [];
or
product = new Array();
End Videos no 43
=================================================================
FAQ: What is difference between array "[]" and "array()" ?
Ans:
var products = "[]";
var products = new Array();
- You can access array elements [values] by using the reference of property.
ex:
document.write(value[2]) => true
document.write(values["1"]) => TV
----------------------------------------------------------------
Array Properties & Method
-------------------------
1. Finding the length of an array, Which is total count of element in array.
Note: You can also use various statements explicitly to read value from array for,
while, for..in, for..of
Syntax:
for(var property in collection)
{
}
Syntax:
for(var value of collection)
{
}
End videos no 44
=================================================================
Dynamically Creating HTML elements:
-----------------------------------
1.HTML Elements can be created in JavaScript by using the DOM method.
pic.src = "imgages/name.jpg";
pic.width ="400";
pic.height= "400";
pic.className = "cssClassName";
4. Add element into page. You can add any element using the DOM method
appendChild();
<figure></figure>
document.querySelector("figure").appendChild(pic);
Note: You have to configure all the functionality using specific event in page.
like-> onload, onclick, onchange ect..
Syntax:
var value= [10,20,30]; <ol></ol>
values.map(function(value){
var li = document.createElement("li");
li.innerHTML = value;
document.querySelector("ol").appendChild("li);
})
Syntax:
var menu = ["Electronics"];
menu.push("footwear"...); ["All", "Electornics", "footwear"]
menu.unshift("All"...); ["All", "Kids", "Electornics", "footwear"]
menu.splice("1,0,"kids"...); ["All","Kids", "Electornics", "footwear"];
Syntax:
var categories = ["All", "Electronics" "Fashion"];
categories.pop(); => ["All", "Electronics"];
categories.shift(); => ["Electronics", "Fashion"];
categories.pop(); => ["All", "Electronics"];
categories.pop(); => ["All", "Fashion"];
Syntax:
categories.sort()
categories.reverse()
End Videos no 45
=================================================================
Object Type
<------------>
Syntax:
var obj= {
"key":value;
"key:: function(){}
}
Syntax:
var product = {
"Name" : "Moble";
"Price" : 3435.43;
document.write('Price=${product.Price}');
- JSON data is kept in separate JSON file that have the extension
".json".
- To access data from JSON file JavaScript provides a "fetch()"
promise.
Syntax:
fetch("url").then(function(reponse){
return response.json();
}).then(function(data){
.. you can use data..
}).catch(function(ex){
...display exception..
}).finally(function(){
.. excutes always..
})
End Videos no : 46
=================================================================
Fetching Data from API Website:
-------------------------------
-nasa.api.gov
-fakestoreapi.com
Fakestore:
- It provides PAI for ERP application[shopping]
- It provides various method for different type of data available in there
database.
Ex:
http://fakestoreapi.com/products
http://fakestoreapi.com/products/categories
End Video No 47
================================================================
Object with Data & Functionality
--------------------------------
Syntax:
var product = {
"key" : value,
"key" : function(){}
FAQ's
1. How to read all keys from an object ?
Ans: By using "for..in" iterator or by using "Object.keys()"
Syntax:
for(var property in object)
{}
Syntax:
typeof object[key] => return value data type.
Syntax:
delete object. Key;
Map Type:
========
- It is also a key and value collection like object.
- Key can be any type.
-Value can be any types.
- It provides all implicit methods for manipulation.
- Hence it is faster than object.
- But it is schema less [structure less].
Method Description
-----------------------------------------------------------------
set() : It configure a new key with value.
get() : It can access value with reference of key.
delete() : It removes a key.
clear() : It removes all keys.
size : It return the count of keys.
has() : It find a key.
keys() : It returns all keys.
values() : It return all values.
entries() : It returns all keys & values.
Syntax:
var topics = new Map();
topics.set(key, value);
topics.get(key);
topics.delete(key);
topics.size;
topics.clear();
topics.keys(); [] of keys
-----------------------------------------------------------------
Syntax:
var now = new Date(); => loads current data & time into memory
SetHourse()
SetMinutes()
SetSecond()
SetMilliSecond()
SetDate()
SetMonth()
SetYear()
End video no 48
================================================================
Interval:
- Timeout will remove the task from memory and release into processes.
- Timeout will execute only once.
-Interval will keep the task in memory and release into process at regular time
intervals.
- You have to remove explicitly.
-----------------------------------------------------------------Summery:
1. Primitive types:
- number
- string
- Boolean
- null
- undefined
- symbol
- bigint
3. Date Type
4. Timer Events
5. JSON
JavaScript Operators
====================
1. Arithmetic operators
+
-
*
/
%
**[power]
++[increment]
--[decrement]
syntax:
2 **3 => 8
var x = 10;
var y = x++; post increment[x=11, y=10]
var y = x--; post decrement[x=9, y=10]
Syntax: Pre Increment, Decrement
Math.PI
Math.cos()
Math.tan()
Math.sin()
Math.sqrt()
Math.pow()
Math.round()
Math.floor()
Math.ceil()
Math.random() ect..
End video no 49
=================================================================
What is difference between "==" & "===" ?
Ans: "==" can campare values of various types.
"===" can compare only identical types i.e same type.
var x = 10;
var y = "10";
x == y // true
x===y //false
5. Special Operators
new : dynamic memory allocation operator
?: : ternary operator
typeof : It return the data type of value stored in reference
delete : It deletes a key from object.
in : It can search for a key in object and return true if found.
void : It discards the return of a function.
yield : It return values of a function generator.
instanceOf : It return true if object belongs to specified class
JavaScript Statements
1. Selection Statements
if, else, switch, case, defualt
2.Looping Statements
for, while, do while
3.Iteration Statements
for..in, for..of
4. Jump Statements
break, continue, return,
5.Exception Handling
try, catch, throw, finally
Function Parameters:
- Parameters are required to modify a function
Syntax:
function Name (param) => param - formal parameter
{}
param = value;
End Videos no 50
----------------------------------------------------------------
Parameter Type
- A function parameter can e any type
a) Primitive
b) Non Primitive
c) Function
- In JavaScript formal parameter is just a reference name, into the parameter you
can store anything.
Syntax:
function demo(ref)
{} => ref -> number, string, Boolean, array, object
Multiple Parameter
- A function can have multiple parameters.
- Every parameter is required and have order dependency.
- If you want to ignore any specific parameter, then you have handle using
undefined type.
syntax:
function demo(..param1, ..param2) => invalid
function demo(..param1, title) => invalid
function demo(title, ..param1, ) => valid
Syntax:
function demo(a,b,c,d)
{}
val values = =[10,20,25,50];
demo(..values)
Note: Rest is about the formal parameter, a single formal parameter allows multiple
arguments.
Spread is about the actual parameters , a single actual value can spread into
multiple formal parameters.
Spread actual value must be an array type.
Rest is also array
Syntax:
function Name(){
return value;
}
Function Closure
FUNCTION Outer()
{
function inner()
{
return value;
}
.. you can access inner value.
}
---------------------------------------------------------------
Function Generator
==================
- A function generator is used to create iterators in computer programming.
- Iterator is a software design pattern used to access elements from a collection
in sequential order.
- Iterator doesn't require condition, counter and initializer.
- Generator is defined using "&" which means zero or more times execution.
- The method "done()" returns true when there is no more value to read.
Syntax:
function * Name(){
yield value;
}
var ref = Name();
ref.next().value => return value
ref.next().done => return true if there are no
more values to red.
Function Call Back
==================
Syntax:
function Name(classBack1, callBack2)
{
}
Name(function(){}, Function(){});
-----------------------------------------------------------------
Function Promise
- Promise Uses an Async technique.
- Async is an unblocking technique that allows the task to perform without blocking
tasks.
- Promise comprise of 3 phases.
a) pending : Initial phase
b) Resolved : It defined using then()
c) Rejected : It is defined using catch()
Syntax:
var refName = Promise(function(resolve, reject){
if(condition)
{
resolve("on success");
} else{
reject("on failure");
}
});
refName.then(function()(){}).catch(function(){})
---------------------------------------------------------------
Arrow Function
- It is a short hand technique for writing a function expression.
- It uses following chars
() function & Its params
=> return and definition
var hello=()=>{
stmt -1;
stmt -2;
}
Ex:
function Hello(uname)
{
document.write(`Hellow ! ${uname}`);
}
1. POPS
- Process Oriented programming System.
- It support low level features
- It can directly interact with hardware services.
- It is faster and used less memory.
Ex: C, Pascal
- Hard to extend
- Not having good dynamic memory
- Not good for reusability
- Not good in separation issues
2. OBPS
- Object Based Programming Systems
- It support reusability, separation
- I have dynamic memory
- Extensibility issues
- No dynamic polymorphism
- No code level security
- no contracts & templates
3. OOPS
- Object Oriented Programming System
- Code reusability
- Code separation
- Code Extensibility
- Code Security
Drawback:
End Videos no 52
=================================================================
JavaScript Modules
==================
- A module is a set of values, functions and classes, which you can import and use
across location.
- It enables code reusability and extensibility.
- You can build a JavaScript library using modules.
- In order to use module you need a module system installed.
- There are various JavaScript module systems.
a) Common JS
b) Require JS
C) UMD (Universal Module Distribution)
d) AMD (Asynchronous Module Distribution)
e) ESMO
- If you are running JavaScript in browser with HTML page then browser have a
default modules system called "ESModule".
Syntax:
<script type="module">
</script>
3. You can configure variable, function and classes in module, but every member in
module is private in access. If you want to access from remote location, then they
must be marked wht "export" keyword.
4. YOu have to import the module and it's member into HTML page by using "import"
statement.[other module systems have different statements]
document.querySelector("p).innerHTML = Welcome();
alert(Hello());
console.log(Welcome());
-----------------------------------------------------------------
Classes
- In computer programming class is a program template.
- A template provide sample data and logic which you can customize and implement
according to requirements.
- If a class is mapping to data requirements then it is referred as "module"
- If a class is mapping to business requirement then it is referred as "entity".
- If a class is action a source for several instances then it is referred as "Blue
Print"
Configuring class:
1. Declaration
class Name
{
}
2. Expression:
Class Members:
- Every JavaScript class can have only the following as class members
1. Property
2. Accessor
3. Contractor
4. Method
FAQ: Why function and variables are not allowed as class members
Ans: Variable and Function are Immutable.
A class member must be always mutable.
Hence variable and function can't be class member.
Property :
-A property is used to store data.
- In JavaScript class property is having just a reference name.
- You can initialize any type of value.
- You can assign any type of value using instance of class.
Syntax;
class Product{
Name = "TV"; -> number, string, Boolean, null array ect
}
let obj = new Product();
obj.Name = "Samsung TV";
console.log(obj.Name);
- Property is mutable.
- A property can changes the behaviour dynamically according to state and
situation.
Accessors:
-Accessor are using to five fine grained control over the property.
- They allow to handle read and write operations on a property.
- There are 2 accessors
a. get() getter is used to read and return value of property.
b. setter is used to assign a new value into property.
Syntax:
get aliasName()
{
return property;
}
set aliasName(newValue)
{
property = newValue;
}
End video no 53
=================================================================
Method
======
- It is used for refactoring the code.
- It is similar to a function but mutable.
- All functionality is same like function.
Syntax:
class Name{
Method(){
}
}
Constructor
===========
- It is a special type of sub-routine using for instantiation.[creating object]
- Every class have a default constructor that creates an object for class.
- JavaScript constructor is "anonymous";
- It is defined with constructor keyword.
Syntax:
class Name{
constructor(){
}
}
let name = ClassName();
- Constructor is executed only once per object.
- JavaScript constructor doesn't support access modifiers, overloading ect.
1. Aggregation
2. Inheritance
- Reusability is the process the member from one class and using in another
classes.
Aggregation:
syntax:
class A
{
// members
}
class B
{
// create instance of class A to access it's members
}
Inheritance:
- You can use "extends" keyword that extends the existing class.
- The new class is known as "Derived" class.
Syntax:
class A {}
- You can access the members of super class using "super" keyword
- This is referred as "Is-A-Relation".
Polymorphism:
End Videos no 54
=================================================================
JavaScript Events
-----------------
- Event is a message sent by sender to it's subscriber in order to notify the
change.
- It follows a software design pattern called "observer".
- Observer is a communication pattern.
Syntax:
function InsertClick() => subscriber
{
}
<button onclick="InsertClick(this,event)">
- "this" sends information about current element, which includes id, name,
className, width, height, src, href ect.
- "event" sends information about current event, which includes client, clientY,
shiftKye, ctrlKey, altKey, ect..
Syntax:
function handleClick(obj, collection)
{
}
1. Mouse Events
2. Keyboard Events
3. Button Events
4. Form Events
5. Touch Events
6. Element state Events
7. Timer Events
8. Clipboard Events ect.
1. Mouse Events:
- onmouseover
- onmouseout
- onmousedown
- onmouseup
- onmousemove
2. Keyboard Events
- onkeyup
- onkeydown
- onkeypress
3. Button Events
- onclick : single click
- ondbclick : double click
- oncontextmenu : right click
- onselectstart : hold down the button and drag to select
Note: If any event you want to disable, then define "return" false.
5. Touch Events
- ontouchstart
- ontouchand
- ontouchmove
7. Timer Events
- setTimeout()
- clearTimeout()
- setInterval()
- clearInterval()
8. Clipboard Events
- oncut
- oncopy
- onpaste
End videos no 55
================================================================
4. Font Event
- onsubmit
- onreset
Syntax:
document.querySelector("button").addEventListener
// action perform
("evenName", functon(){
})
1. Query String
- A query string is appended into URL with a key and value reference.
?key=value
- Any form can submit it's data into query string on "Get" request.
- You can access querying using "location.search"
Ex:
1. Add a new folder
"State"
2. Add files
home.html
Local Storage
-------------
- Every browser have a local storage.
- It is permanent storage.
- It is available even after you device shut-down.
- you have to delete manually from browser memory.
- It is accessible across all tabs in browser.
Syntax:
localStorage.setItem("key","value");
Session Storage
---------------
- It is temporary storage.
- It is not accessible to other tabs.
- It is removed when browser is closed.
Syntax:
sessionStorage.setItem("key","value");
sessionStorage.removeItem("key");
Cookies
-------
- Cookies are simple text documents.
- Client related information can be sorted in a cookie file and used later by page.
- Cookies need to be enabled in browser.
- You can verify cookie status by using
*****************************************************************