Learn JavaScript ES6 Modules in 6 minutes!

Learn JavaScript ES6 Modules in 6 minutes!

Bro Code

11 месяцев назад

21,503 Просмотров

#javascript #tutorial #course

// ES6 Module = An external file that contains reusable code
// that can be imported into other JavaScript files
// Can contain variables, classes, functions ... and more
// Introduced as part of ECMAScript 2015 update

// ---------- index.js ----------

import {PI, getCircumference, getArea, getVolume} from './mathUtil.js';

console.log(PI);
const circumference = getCircumference(10);
const area = getArea(10);
const volume = getVolume(10);

console.log(`${circumference.toFixed(2)}cm`);
console.log(`${area.toFixed(2)}cm^2`);
console.log(`${volume.toFixed(2)}cm^3`);

// ---------- mathutil.js ----------

export const PI = 3.14159;

export function getCircumference(radius){
return 2 * PI * radius;
}

export function getArea(radius){
return PI * radius * radius;
}

export function getVolume(radius){
return 4 * PI * radius * radius;
}

Тэги:

#javascript #javascript_tutorial #javascript_full_course #javascript_course #course #full_course #web_development #web_developer #software_engineer #software_engineering #coding_tutorial #learn_to_code #tutorial #html #css #modules #ES6_modules #ES6
Ссылки и html тэги не поддерживаются


Комментарии: