function addTax(total) { return total * 1.05; }
(Version 2, possibly an updated version)
function addTax(total) { return total * 1.05; }
let modal = document.querySelector('#result'); setTimeout(function(){ modal.classList.remove('hidden); }, 10000); console.log('Results shown');
for (var i = 1; i <= 4; i++) { setTimeout(function () { console.log(i); }, i * 10000); }
for (var i=1; i<=4; i++){ (function(i){ setTimeout(function(){ console.log(j); }, j*1000); })(j) }
while (var i=1; i<=4; i++) { setTimeout(function() { console.log(i); }, i*1000); }
for (var i=1; i<=4; i++) { {function(j) { setTimeout(function(){ console.log(j); }, j*1000); })(i) }
for (var j=1; j<=4; j++) { setTimeout(function() { console.log(j); }, j*1000); }
let discountPrice = function(price) { return price * 0.85; };
let discountPrice(price) { return price * 0.85; };
let function = discountPrice(price) { return price * 0.85; };
discountPrice = function(price) { return price * 0.85; };
var Storm = function () {}; Storm.prototype.precip = 'rain'; var WinterStorm = function () {}; WinterStorm.prototype = new Storm(); WinterStorm.prototype.precip = 'snow'; var bob = new WinterStorm(); console.log(bob.precip);
'use strict'; function logThis() { this.desc = 'logger'; console.log(this); } new logThis();
let roadTypes = ['street', 'road', 'avenue', 'circle'];
console.log(typeof(42));
function addNumbers(x, y) { if (isNaN(x) || isNaN(y)) { } }
for (var i = 0; i < 5; i++) { console.log(i); }
var a = ['dog', 'cat', 'hen']; a[100] = 'fox';
Map.prototype.size
returns the number of elements in a Map, whereas Object does not have a built-in method to return its size.
const dessert = { type: 'pie' }; dessert.type = 'pudding';
class X { get Y() { return 42; } }
sum(10, 20); diff(10, 20); function sum(x, y) { return x + y; } let diff = function (x, y) { return x - y; };
Records in an object can be retrieved using their key which can be any given value (e.g. an employee ID, a city name, etc), whereas to retrieve a record from an array we need to know its index.
[] == [];
var v = 1; var f1 = function () { console.log(v); }; var f2 = function () { var v = 2; f1(); }; f2();
let arr = [];
var start = 1;
if (start === 1) {
let end = 2;
}
const x = 6 % 2;
const y = x ? 'One': 'Two';
var a; var b = (a = 3) ? true : false;
<p class="pull">lorem ipsum</p>
Document.querySelector('class.pull')
document.querySelector('.pull');
Document.querySelector('pull')
Document.querySelector('#pull')
let answer = true; if (answer === false) { return 0; } else { return 10; }
var start = 1; function setEnd() { var end = 10; } setEnd(); console.log(end);
function sayHello() { console.log('hello'); } console.log(sayHello.prototype);
function printA() { console.log(answer); var answer = 1; } printA(); printA();
class X { get Y() { return 42; } } var x = new X();
'use strict'; function logThis() { this.desc = 'logger'; console.log(this); } new logThis();