// to run currently open .js file in VSCode, hit 'Run->Run Without Debugging' (Ctrl+F5) // Node.js needs to be installed, .js file needs to be opened from folder /* { "version": "2.0.0", "tasks": [ { "label": "Show in console", "type": "shell", "command": "node ${file}", "group": { "kind": "build", "isDefault": true }, "presentation": { "reveal": "always", "clear": true, "echo": false, "showReuseMessage": false } } ] } */ //console.log(String('hello lmao wtf').split('.')); const sumArray = (arr) => arr.reduce((prev, curr) => prev + curr); myArr = [3, 7, 9, 12]; console.log("the sum of %O array is: %d", myArr, sumArray(myArr)); console.log("%s is %d years old", 'Jesus', 33); console.log("%chello, %cworld%c!", "color: blue;", "font-size: 2em;", "/* no CSS rule /*"); // class-like object function Person(name) { this.name = name; // public data member var _age; // private data member function privFunc() {} this.setAge = function(n) { _age = n; } this.getAge = function() { return _age; } // this.age would be undefined age is 'var'ed' } Person.prototype.funkyName = function() { return this.name + 'ley' } // public method to all var kyle = new Person("Kyle"); console.log(kyle.funkyName()); // convert list to array function list() { return Array.prototype.slice.call(arguments) } let list1 = list(1, 2, 3) // will get converted to [ 1, 2, 3 ] console.log(list1); // split string into words var str1 = "this is a string, ayy"; var words = str1.split(/,| /).map(w => console.log(w)); // .format() implement into built-in String object String.prototype.format = function() { var formatted = this; for (var arg in arguments) { // console.log("arg is %s", arg); formatted = formatted.replace("{" + arg + "}", arguments[arg]); } return formatted; }; console.log("{0} is dead, but {1} is alive!".format("ASP", "ASP.NET")); // .format implement into built-in String object using ES6 declarative approach String.prototype.format = function() { return [...arguments].reduce((p,c) => p.replace(/%s/,c), this); }; console.log('Is that a %s or a %s?... No, it\'s %s!'.format('plane', 'bird', 'SOman')); console.log((function(){}).constructor); fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo').then(res => { return res.json(); }).then(price => console.log(price)); const { getName } = require('./mymodule'); console.log(getName()); console.log("ayy lmao".toUpperCase());