Tutorial by Examples

Number('0') === 0 Number('0') will convert the string ('0') into a number (0) A shorter, but less clear, form: +'0' === 0 The unary + operator does nothing to numbers, but converts anything else to a number. Interestingly, +(-12) === -12. parseInt('0', 10) === 0 parseInt('0', 10) will c...
String(0) === '0' String(0) will convert the number (0) into a string ('0'). A shorter, but less clear, form: '' + 0 === '0'
The double-negation !! is not a distinct JavaScript operator nor a special syntax but rather just a sequence of two negations. It is used to convert the value of any type to its appropriate true or false Boolean value depending on whether it is truthy or falsy. !!1 // true !!0 ...
JavaScript will try to automatically convert variables to more appropriate types upon use. It's usually advised to do conversions explicitly (see other examples), but it's still worth knowing what conversions take place implicitly. "1" + 5 === "15" // 5 got converted to string. ...
Boolean(0) === false Boolean(0) will convert the number 0 into a boolean false. A shorter, but less clear, form: !!0 === false
To convert a string to boolean use Boolean(myString) or the shorter but less clear form !!myString All strings except the empty string (of length zero) are evaluated to true as booleans. Boolean('') === false // is true Boolean("") === false // is true Boolean('0') === fals...
In JavaScript, all numbers are internally represented as floats. This means that simply using your integer as a float is all that must be done to convert it.
To convert a float to an integer, JavaScript provides multiple methods. The floor function returns the first integer less than or equal to the float. Math.floor(5.7); // 5 The ceil function returns the first integer greater than or equal to the float. Math.ceil(5.3); // 6 The round function...
parseFloat accepts a string as an argument which it converts to a float/ parseFloat("10.01") // = 10.01
Boolean(...) will convert any data type into either true or false. Boolean("true") === true Boolean("false") === true Boolean(-1) === true Boolean(1) === true Boolean(0) === false Boolean("") === false Boolean("1") === true Boolean("0") === t...
Array.join(separator) can be used to output an array as a string, with a configurable separator. Default (separator = ","): ["a", "b", "c"].join() === "a,b,c" With a string separator: [1, 2, 3, 4].join(" + ") === "1 + 2 + 3 + 4&q...
This way may seem to be uselss becuase you are using anonymous function to acomplish something that you can do it with join(); But if you need to make something to the strings while you are converting the Array to String, this can be useful. var arr = ['a', 'á', 'b', 'c'] function upper_lower (...
ValueConverted To StringConverted To NumberConverted To Booleanundefinded"undefined"NaNfalsenull"null"0falsetrue"true"1false"false"0NaN"NaN"false"" empty string0false" "0true"2.4" (numeric)2.4true"test" (non nu...

Page 1 of 1