From * To Javascript
November 28, 2018 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
programming languages, public.
Educators must contend with students’ prior knowledge of a subject. Sometimes the prior knowledge is advantageous—but not always. What we “know” may be wrong or incomplete. The same is true with programming languages. When learning a new language, you must contend with the baggage you bring from other languages you know.
Suppose you are C or Java programmer and you see this bit of Javascript code:
function isBetween(lo, hi, x) {
return
lo <= x &&
x <= hi;
}
console.log(isBetween(0, 10, 5));
What output do you expect to see?Probably you expect to see a boolean. In this case,
true. But you are wrong. The output is
undefined.
Your C or Java knowledge has conditioned you to mostly ignore whitespace and mentally parse statements using semicolons. But Javascript automatically inserts semicolons for you when interpreting your code. In particular, Section 7.9 of the ECMA specification says this:
When a continue, break, return, or throw token is encountered and a LineTerminator is encountered before the next token, a semicolon is automatically inserted after the continue, break, return, or throw token.
Whoops. I long for the day when we no longer manually format our code with whitespace, but leave it to the editor to apply our styles to the token stream. I still want text, just not spaces, tabs, and linebreaks.