{"id":140,"date":"2026-05-05T11:16:26","date_gmt":"2026-05-05T11:16:26","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=140"},"modified":"2026-05-05T11:16:27","modified_gmt":"2026-05-05T11:16:27","slug":"modules-import-export","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export","title":{"rendered":"Modules Import\/Export"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<br>Modules in JavaScript allow developers to split code into reusable, organized, and maintainable files. Using import and export, you can share functions, variables, or classes between different files. This makes large projects easier to manage and improves code readability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What are JavaScript Modules<br>A module is simply a JavaScript file that contains code you want to reuse. Each module has its own scope, which helps avoid conflicts between variables and functions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why Use Modules<br>Modules help keep code clean and organized<br>They allow reuse of functions and logic across files<br>They improve maintainability in large projects<br>They reduce the risk of naming conflicts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Exporting in JavaScript<br>Export is used to make variables, functions, or classes available to other files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Named Export<br>You can export multiple items from a file by name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>export const name = &#8220;Ali&#8221;<br>export function greet() {<br>return &#8220;Hello&#8221;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Default Export<br>A file can have one default export<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>export default function welcome() {<br>return &#8220;Welcome to JavaScript&#8221;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Importing in JavaScript<br>Import is used to bring exported code into another file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Import Named Exports<br>import { name, greet } from &#8220;.\/file.js&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Import Default Export<br>import welcome from &#8220;.\/file.js&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Import Everything<br>import * as utils from &#8220;.\/file.js&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using Modules in HTML<br>To use modules in the browser, you must define the script type as module<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>script type=&#8221;module&#8221; src=&#8221;app.js&#8221; script<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Best Practices<br>Use meaningful file names<br>Keep modules small and focused<br>Use default export for main functionality<br>Use named exports for multiple utilities<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common Use Cases<br>Sharing utility functions across files<br>Organizing large applications into smaller parts<br>Reusing code in different projects<br>Building scalable frontend and backend applications<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<br>JavaScript modules using import and export are essential for writing clean and scalable code. They help developers structure applications efficiently and promote code reuse.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Advanced JavaScript > ES6+ Features > Modules Import\/Export<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777979745959\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777979745742\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-140","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Modules Import\/Export - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Modules Import\/Export - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-05T11:16:27+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=modules-import-export\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=modules-import-export\",\"name\":\"Modules Import\\\/Export - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-05T11:16:26+00:00\",\"dateModified\":\"2026-05-05T11:16:27+00:00\",\"description\":\"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=modules-import-export#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=modules-import-export\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=modules-import-export#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced JavaScript > ES6+ Features > Modules Import\\\/Export\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Modules Import\/Export - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export","og_locale":"en_US","og_type":"article","og_title":"Modules Import\/Export - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-05T11:16:27+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export","url":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export","name":"Modules Import\/Export - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-05T11:16:26+00:00","dateModified":"2026-05-05T11:16:27+00:00","description":"Learn JavaScript modules with import and export to organize code, improve reuse, and build scalable web applications easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=modules-import-export#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Advanced JavaScript > ES6+ Features > Modules Import\/Export"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}