0% found this document useful (0 votes)
11 views6 pages

ES6 Module Programming Guide

The document explains modular programming in JavaScript using ES6 features, including modules, exports, and imports. It provides examples of normal and default exports, as well as functions, classes, and arrow functions. The document emphasizes code reusability and reducing redundancy through modular design.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

ES6 Module Programming Guide

The document explains modular programming in JavaScript using ES6 features, including modules, exports, and imports. It provides examples of normal and default exports, as well as functions, classes, and arrow functions. The document emphasizes code reusability and reducing redundancy through modular design.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

You might also like