Show pageOld revisionsBacklinksExport to PDFBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== JavaScript: Best practices ====== <code javascript Logging> console.log('%c Test', 'color:orange'); console.log({var1, var2, var3}); console.table([var1, var2, var3]); console.time('timerName'); ... code ... console.timeEnd('timerName'); console.trace('comment'); </code> <code javascript Strings> var a = varb + ' pero ' + varc; // Bad var a = '${varb} pero ${varc}'; // Good function test({prop1, prop2 prop3}) { return '${prop1}, ${prop2}, ${prop3}'; } //or function test(array) { const {prop1, prop2 prop3} = array; return '${prop1}, ${prop2}, ${prop3}'; } //usage test(array); //array with field names as above const var1 = var2 > 5 ? 'text1' : 'text2'; </code> <code javascript Arrays> test = ['d','e','f']; //push test = [...test,'g','h','i']; //shift test = ['a','b','c',...test]; //insert test = ['1','2',...test,'3','4']; const high = array.filter(v => v > 100); const tax = array.map(v => v * 1.25); </code> development/js/code_examples.txt Last modified: 2019/10/31 09:04by 127.0.0.1