Syntax Comparison of Javascript, Perl, PHP, and VBA

  Javascript Perl PHP VBA
         
user defined function function name (arg1, arg2 ...) { sub name { [no args] function name ($arg1, $arg2, ..., $argn) { function funcname (arg1 as type, arg2 as type...)

sub subname()

call that function name (arg1, arg2) &name name($arg1, $arg2...) variable=funcname( arg1..)
"()" required when passing args.

subname
cannot call with "()"

return value

return(expression) =val of expression

return(); = undefined

fall off end of function = undefined

value of last expression evaluated return $retval; Set funcname

sub does not return a value

how end function? } } } End Function
End Sub
arrays start with 0/1? 0 0 0 0
require ; at line end optional if complete statement formatted on line by itself yes yes, I think no
string concatenation string + string string . string string . string string & string
require {} after if statements no yes no no
if syntax if (expr) if { ...} [{ is required]..endif if (expr) If ... End If
else if syntax else if elsif elseif ElseIf
how reference variables variable $variable $variable variable
equality test == == == =
comments // to end of line OR

/* comment */ may span multiple lines, but cannot be nested

# to end of line // or # to end of line or end of PHP code block, whichever comes first

/* comment */ may span multiple lines, but cannot be nested

Rem or '

to comment multiple lines use the line continuation character, " _"

additional notes     Any numeric non-zero numeric value is TRUE, zero is FALSE. Be sure to note that negative values are non-zero and are thus considered TRUE! The empty string and the string "0" are FALSE; all other strings are TRUE. With non-scalar values (arrays and objects) - if the value contains no elements it's considered FALSE, otherwise it's considered TRUE.