Un trucchetto al giorno per mantenerti allenato o per conoscere qualcosa di nuovo sul magico mondo di JavaScript.
118
How to get the number of unique characters in a string
2021-07-22 - JavaScript
1// JS Tip of the Day2// How to get the number of unique characters in a string34const hero ="I'm the night!";56// Case sensitive7console.log(newSet(hero).size);// 1189// Case insensitive10console.log(newSet(hero.toLowerCase()).size);// 10
1// JS Tip of the Day2// Intl API Examples34const number =789123.456;56// Number format7Intl.NumberFormat("en-US").format(number);8// 789,123.4569Intl.NumberFormat("it-IT").format(number);10// 789.123,4561112// Currency format13newIntl.NumberFormat('en-US',{style:'currency',currency:'USD'}).format(number);14// $789,123.4615newIntl.NumberFormat('it-IT',{style:'currency',currency:'EUR'}).format(number);16// €789.123,461718// Unit format19const literConfig ={style:'unit',unit:'liter'};20newIntl.NumberFormat('en-US', literConfig).format(number);21// 789.123,46 L22newIntl.NumberFormat('en-US',{...literConfig,unitDisplay:'long'}).format(number);23// 789.123,46 liters24newIntl.NumberFormat('it-IT', literConfig).format(number);25// 789.123,46 l26newIntl.NumberFormat('it-IT',{...literConfig,unitDisplay:'long'}).format(number);27// 789.123,46 litri2829const meterConfig ={style:'unit',unit:'meter-per-second'};30newIntl.NumberFormat('en-US', meterConfig).format(number);31// 789.123,456 m/s"32newIntl.NumberFormat('en-US',{...meterConfig,unitDisplay:'long'}).format(number);33// 789.123,456 meters per second34newIntl.NumberFormat('it-IT', meterConfig).format(number);35// 789.123,456 m/s"36newIntl.NumberFormat('it-IT',{...meterConfig,unitDisplay:'long'}).format(number);37// 789.123,456 metri per secondo
1// JS Tip of the Day2// Live or static reference of ESModule import3// https://jakearchibald.com/2021/export-default-thing-vs-thing-as-default/45// These give you a live reference to the exported thing(s):6import{ thing }from'./module.js';7import{ thing as otherName }from'./module.js';8import*as modulefrom'./module.js';9const module =awaitimport('./module.js');10// This assigns the current value of the export to a new identifier:11let{ thing }=awaitimport('./module.js');1213// These export a live reference:14export{ thing };15export{ thing as otherName };16export{ thing asdefault};17exportdefaultfunctionthing(){}18// These export the current value:19exportdefault thing;20exportdefault'hello!';
Hai in mente un progetto e vorresti realizzarlo? Sei interessato a migliorare le tue competenze o quelle del tuo team in ambito di programmazione e sviluppo?