Imports and Modules

  • Imports let you break your code into files that reference each other
  • Also let you import parts of a library (but not the whole thing!)
  • Using imports also opts you into using modules
  • Modules make sure that variables and functions from one file don't "leak"
  • Let you write bigger projects without worrying about "collisions"
// file a.js
import { addNumbers } from "./b"


// -------------------------------
//file b
export function addNumbers(a,b) {
    return a + b

8 / 10