Javascript - Function Problems

Javascript is a highly non-standard language. Basic function calls demonstrate this.

Default Parameter Values | By Value vs By Reference | Function Definitions


Default Parameter Values

Most languages provide a simple technique to provide default values for function parameters. The following technique works fine in Chrome and Firefox, but causes a hard error in Microsoft IE and Microsoft Edge. The "error" is Column 70 is the equals sign (=).

Using an equals sign (=) is part of ECMAScript 6 which was mostly supported by browsers after 2018. (This page was started 01-2017.)

w3schools.com suggests the following syntax.

However, this should also work (observed on github).


By Value vs By Reference

According to w3schools.com, Basically,

This is a real pain, all the better languages allow the programmer to control whether arguments are passed "by value" or "by reference".


Function Definitions

According to w3schools.com, when functions are defined, a semicolon is NOT required after the final curly brace. However, when a variable is assigned to an anonymous function (a function without a name), that is actually an executable statement and a semicolon IS required. However, in all the browsers I've tried, the final semicolon is NOT required in either case.

When "use strict"; is specified, then the var is required for both regular variables and function variables. However, when adding methods (subroutines) to objects, it is not


Author: Robert Clemenzi
URL: http:// mc-computing.com / Languages / Javascript / Function_problems.html