New javascript features overview. Part three

Home » Tutorials » JavaScript » New javascript features overview. Part three
In last part of new javascript features lessons we will talk about modules.
Modules let us to create more structured code. It’s important to understand, modules can be exported and imported. Keywords export and import use for it.

Code lesson

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    

    <!-- <script src="class.js"></script> -->

    <script type="module">
        // import {sayHi, Programmer, cities} from './class.js';
        import * as myModule from './class.js';
        let kam = new myModule.Programmer();
        console.log(kam);
        console.log(myModule.cities);
        myModule.sayHi();
    </script>

</body>
</html>

Code lesson

'use strict'
export class Programmer {
    name = 'Камиль';
    lang = 'javascript';

    constructor(age) {
        this.age = age;
    }

    sayHi() {
        console.log(`${this.name}, привет`);
    }
}

export const cities = [
    'Москва',
    'Санкт-Петербург'
];

export function sayHi() {
    console.log('Привет');
}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This