Number(t)
instead. 61
62 if (typeof options.expires === 'number') {
63 var days = options.expires, t = options.expires = new Date();
64 t.setTime(+t + days * 864e+5); 65 }
66
67 return (document.cookie = [
String(obj)
instead. 31 }
32
33 function toStr(obj) {
34 return (typeof obj == STRING) ? obj : "" + obj; 35 }
36
37 function hashObject(obj) {
Number(exp)
instead. 32 */
33 function decimalAdjust(type, value, exp) {
34 // If the exp is undefined or zero...
35 if (typeof exp === 'undefined' || +exp === 0) { 36 return Math[type](value);
37 }
38 value = +value;
Number(value)
instead. 35 if (typeof exp === 'undefined' || +exp === 0) {
36 return Math[type](value);
37 }
38 value = +value; 39 exp = +exp;
40 // If the value is not a number or the exp is not an integer...
41 if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
Number(exp)
instead. 36 return Math[type](value);
37 }
38 value = +value;
39 exp = +exp; 40 // If the value is not a number or the exp is not an integer...
41 if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
42 return NaN;
Prefer using explicit casts by calling Number
, Boolean
, or String
over using operators like +
, !!
or "" +
.
This is considered best practice as it improves readability.
const b = !!foo;
// The `+` operator does not change the value of its operand
// unless it's already a number.
let n = +foo;
n = 1 * foo;
const s = "" + foo;
const b = Boolean(foo);
const n = Number(foo);
const s = String(foo);