This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { currentUsers, tasks } from './export_with_alias.js' | |
// This will import the currentUsers and tasks arrays into the module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const users = ['Ajay', 'Akash', 'Raman']; | |
const tasks = ['write article', 'practice', 'read docs']; | |
export { users as currentUsers, tasks }; | |
// This way the array 'users' will be exported as 'currentUsers' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. exporting with the defination | |
export default function logUser() { | |
console.log(user); | |
} | |
/* OR */ | |
// 2. Exporting at the end of the file | |
function logUser() { | |
console.log(user); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Named export | |
// a) Exporting one by one | |
const ids = [1, 2, 3, 4]; // Not availiable outside this file | |
export const users = ['Ajay', 'Akash', 'Raman']; | |
export const tasks = ['write article', 'practice', 'read docs']; | |
/* Here, we are exporting the variables one by one in their declaration | |
but, we can also export them in a single line as: */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const users = ['Ajay', 'Akash', 'Raman']; | |
const tasks = ['write article', 'practice', 'read docs']; | |
export { users, tasks }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const users = ['Ajay', 'Akash', 'Raman']; | |
export const tasks = ['write article', 'practice', 'read docs']; | |
const ids = [1, 2, 3, 4]; // Not availiable outside this file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Hi'); // prints: Hi | |
setTimeout(function() { | |
console.log('There'); // prints: There | |
}, 0); | |
console.log('Peeps!'); // prints: Peeps! | |
// The callback function inside the setTimeout() gets executed at the end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(1) { | |
/* Warning: blocking code! */ | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const url = 'https://jsonplaceholder.typicode.com/posts'; | |
fetch(url, { | |
method: 'POST', | |
body: JSON.stringify({ | |
title: 'foo', | |
body: 'bar', | |
userId: 1 | |
}), | |
headers: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const url = 'https://jsonplaceholder.typicode.com/todos/1'; | |
fetch(url) | |
.then(response => response.json()) | |
.then(json => { | |
console.log(json); | |
/* prints on success: | |
{ | |
"userId": 1, | |
"id": 1, |