The following are valid:
$someVariable _someVariable some_variable somèvariable
The function variable uses a reserved JavaScript keyword, someVariable and 1Variable both start with invalid characters, and some*variable uses an invalid character, a JavaScript operator (*), as part of the variable name. All invalid names generate JavaScript errors.
The identifiers are converted as follows:
The variable some-month becomes someMonth, using CamelCase notation.
The function theMonth becomes getTheCurrentMonth, using relevant verbs and other distinguishing information.
The const current-month becomes CURRENT-MONTH, using constant-width uppercase letters.
The variable summer-month becomes summerMonths, maintaining consistency between the array of items and variable name.
The MyLibrary-afunction function becomes mylibraryFunctionverbFunctionname.
Important point to remember: conjugation is the bane of coders. Use a backslash before the inner single quote so that itâ??s interpreted literally, and not end-of-string:
var someString = â??Who once said, â??Only two things are infinite, the universe and human stupidity, and I\â??m not sure about the former.â?â??;
The following code would work:
var fltNumber = 432.54; var intNumber = parseInt(fltNumber); var octNumber = parseInt(intNumber,2); var hexNumber = parseInt(intNumber,16);
The function parseInt returns the decimal base integer of the floating-point number, which is 432. It can also take a second parameter, specifying base: 8 for octal and 16 for hexidecimal.
Ah, trick question here. Passing a variable thatâ??s not been declared to a function, user function, or JavaScript function results in a JavaScript error, so your function code will never need to test for this.
To test to see whether the value has been set, use a conditional statement:
function test(a) { if (a) { // some code } }