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
/* Change Array length to 0 */ | |
let arr = [1, 2, 3, 4, 5]; | |
// Change array length to 0 | |
arr.length = 0; | |
console.log(arr); | |
// [] |
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
var x = 10; | |
var y = "10"; | |
// Case 1: when the variables are added | |
console.log(x + y); | |
// Output: 1010 | |
// Case 2: when the variables are subtracted | |
console.log(x - y); | |
// Output: 0 |
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
// To import a default export | |
import <default_value> from '<package-name>'; | |
/* OR */ | |
// To import a named export | |
import { <named_export_value> } from '<package-name>'; |
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 lodash from 'lodash'; | |
// We can also import specific functions using the format: | |
import { isArray } from 'lodash'; | |
// We can also import other files or JS entry points from a package: | |
import map from 'lodash/map'; |
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 * as moduleContent from '<someModule>' | |
// This will import the entire content of the specified module into the current 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
import { users as currentUsers, tasks } from './export_in_single_line.js'; | |
// This will import users as currentUsers from the file 'export_in_single_line.js' |
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 * as moment from 'moment'; | |
// This will import the entire module's content into the file and the functions/variables can be used like: | |
// moment().format(); |
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 logUser from './default_export.js'; | |
// This will import the function logUser into this 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
import <default_export_value> from '<path_of_module_from_current_module>'; | |
// path can be relative or absolute depending upomn the configuration of the project |
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. Import one or more named exports from the module | |
// Syntax | |
import { <named_export_value> } from '<path_of_module_from_current_module>'; | |
// path can be relative or absolute depending upon the configuration of the project | |
// For Example: | |
import { users, tasks } from './export.js'; | |
// This will import the users and tasks arrays into the current module |
NewerOlder