Questions

  1. Of the following identifiers, which are valid, which are not, and why?

    $someVariable
    _someVariable
    1Variable
    some_variable
    somèvariable
    function
    .someVariable
    some*variable
  2. Convert the following identifiers using the conventions outlined in the first section of the chapter:

    var some_month;
    function theMonth // function to return current month
    current-month // a constant
    var summer_month; // an array of summer months
    MyLibrary-afunction // a function from a JavaScript package
  3. Is the following string literal valid? If not, how would you fix it?

    var someString = ‘Who once said, “Only two things are infinite, the universe and human stupidity, and I’m not sure about the former.”’
  4. Given a number, 432.54, what JavaScript returns the integer component of the number, and then finds the hexadecimal and octal conversion?

  5. You create a JavaScript function in a library that can be used by other applications. A parameter, someMonth, is passed to the function. How would you determine whether it’s null or undefined?

Answers are provided in the appendix.

Get Learning JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.