While looking at the jslint code conventions I saw this line:
total = subtotal + (+myInput.value);
What is the purpose of the second '+'?
The $() function The dollar function, $(), can be used as shorthand for the getElementById function. To refer to an element in the Document Object Model (DOM) of an HTML page, the usual function identifying an element is: document.
The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
JavaScript is actually interpreted line by line.
JavaScript statements are composed of: Values, Operators, Expressions, Keywords, and Comments.
The unary plus is there for completeness, compared with the familiar unary minus (-x). However it has the side effect, relied upon here, of casting myInput.value into a Number, if it's something else such as a String:
alert(1+'2'); // 12
alert(1+(+'2')); // 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With