Es6 :ecmascript6:
----------------
modular programming:
--------------------
a complete js programming we can with in a modules .
module:
------
a module is a js include a set of js statements like ,functions,classes,variables
etc..
->module are used to recude code rendendency
->code reusability.
->export :
->normal export
->export default
->import
->normal importing
->default import
ex:
---
[Link]:
-----
export let name='sumanth'
[Link]:
--------
import {name} from './[Link]'
[Link](name)
output:
-----
D:\frontend\11-12(new)\Js>node [Link]
sumanth
Ex:
---
cls1:
----
let name='sumanth'
export default name
[Link]:
------
import name from './[Link]'
[Link](name)
output:
-----
D:\frontend\11-12(new)\Js>node [Link]
sumanth
functions:
----------
Ex:
---
cls1:
----
export function sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
cls2:
----
import {sum} from './[Link]'
sum(10,20,30,40)
output:
-------
D:\frontend\11-12(new)\Js>node [Link]
Sum of all the given values : 100
Q1,write a js logic to get same same output like above with out using the forloop.
Ex:
--
cls1:
---
export default function sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
cls2:
----
import sum from './[Link]'
sum(10,20,30,40)
Arrow function:
---------------
cls1:
----
export const sum = (...arg)=>{
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
cls2:
----
import {sum} from './[Link]'
sum(10,20,30,40)
Ex:
--
cls1:
---
const sum = (...arg)=>{
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
export default sum
cls2:
---
import sum from './[Link]'
sum(10,20,30,40)
class:
-----
cls1:
---
export class Addition{
sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
}
cls2:
----
import {Addition} from './[Link]'
// sum(10,20,30,40)
let object=new Addition()
[Link](10,20,30,40)
Ex:
---
export default class Addition{
sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
}
cls2:
----
import Addition from './[Link]'
// sum(10,20,30,40)
let object=new Addition()
[Link](10,20,30,40)
no two [Link],vaiable will not be export default:
------------------------------------------------------------
cls1;
----
const sum = (...arg)=>{
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
export default sum
export default class Addition{
sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
}
cls2:
----
import Addition from './[Link]'
// sum(10,20,30,40)
let object=new Addition()
[Link](10,20,30,40)
Ex:
---
cls1:
----
export const sum = (...arg)=>{
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
export default class Addition{
sum(...arg){
let count=0
for (let x of arg){
count +=Number(x)
}
[Link]('Sum of all the given values : ',count)
}
}
cls2:
-----
import Addition ,{sum} from './[Link]'
// import {sum} from './[Link]'
sum(20,50,30,40)
let object=new Addition()
[Link](10,20,30,40)
output:
------
D:\frontend\11-12(new)\Js>node [Link]
Sum of all the given values : 140
Sum of all the given values : 100