Skip to content

Instantly share code, notes, and snippets.

View rajat2502's full-sized avatar
🏠
Working from home

Rajat Verma rajat2502

🏠
Working from home
View GitHub Profile
/* Change Array length to 0 */
let arr = [1, 2, 3, 4, 5];
// Change array length to 0
arr.length = 0;
console.log(arr);
// []
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
// To import a default export
import <default_value> from '<package-name>';
/* OR */
// To import a named export
import { <named_export_value> } from '<package-name>';
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';
import * as moduleContent from '<someModule>'
// This will import the entire content of the specified module into the current module
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'
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();
import logUser from './default_export.js';
// This will import the function logUser into this module
import <default_export_value> from '<path_of_module_from_current_module>';
// path can be relative or absolute depending upomn the configuration of the project
// 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