Skip to content

Instantly share code, notes, and snippets.

@biswajitpaul01
Created November 1, 2018 18:05
Show Gist options
  • Save biswajitpaul01/fa1ca25574f82d24df0057332a9ab049 to your computer and use it in GitHub Desktop.
Save biswajitpaul01/fa1ca25574f82d24df0057332a9ab049 to your computer and use it in GitHub Desktop.
Javascript Import Export
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Javascript Import Export Module Example</title>
</head>
<body>
<script type="module">
import { square, diag } from './assets/js/lib.js';
console.log("Square: " + square(11));
</script>
<script type="module" src="assets/js/main.js"></script>
</body>
</html>
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
import { square, diag } from './lib.js';
console.log(square(11));
console.log(diag(4, 3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment