Export a variable by default using JavaScript

Let's assume that we want to export the following variable:

javascript
let tees = [
    {
        color: 'pink',
        price: 10
    },
    {
        color: 'red',
        price: 20
    },
    {
        color: 'black',
        price: 30
    }
];

Default export

To export the variable by default:

javascript
let tees = [
    {
        color: 'pink',
        price: 10
    },
    {
        color: 'red',
        price: 20
    },
    {
        color: 'black',
        price: 30
    }
];

export default tees;

Then, we can import the variable:

javascript
import tees from './tees';

Export

javascript
export let tees = [
    {
        color: 'pink',
        price: 10
    },
    {
        color: 'red',
        price: 20
    },
    {
        color: 'black',
        price: 30
    }
];

Then, we can import the variable:

javascript
import { tees } from './tees';

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.