JavaScript: Feature Range
Page 3
Feature Range
Introduction
Quickly learn about forty different JavaScript operators, keywords, built-in functions and other features with this simple section. JavaScript file, solutions.js processes and displays each example below.
Learn about operators including
mathematical, comparison, type, ternary,
logical and bitwise operators.
See bit shifts, rounding, modulus operations,
functions, properties,
functions as properties, the typeof
operator, and
automatic type conversion.
See
built in functions such as
square root, power (exponentiation), sine, maximum, filter
and reducing.
Operators
Operators with JavaScript, often resemble mathematical operators. JavaScript includes the following operators.
= +, -, /, *, **, %, ++, --
Operator %
, processes modulus.
See modulus operator results.
Operator **
, applies exponentiation.
Operator +
, adds numbers and concatenates strings.
Comparison Operators
Operator
==
, compares values.
Operator ===
, compares values AND types.
Type Operators
Operator typeof
returns a variable's type.
Operator instanceof
returns true if an object's type equals
an instance of a particular object type.
Ternary Operator
The ternary operator includes three
terms; the condition, plus true or false options.
The following psuedocode returns y
if condition
evaluates to true.
The following psuedocode returns n
if condition
evaluates to false.
varName = (condition) ? true:false;
You may substitute any boolean condition for condition
, in the previous psuedocode.
For example try (N_MAX > 6)
:
const N_MAX = 4; var n = (N_MAX > 6) ? true:false;
For example try N_MAX < 2)
where the result's
a function, then call the function.
function const N_MAX = 4; var n = (N_MAX < 2) ? "yes":"no";
Tap to See Results
The aqua box displays just yes
or no
.
The violet box calls a function to
display information.
const N_MAX = 4; var nGreaterThanFour = (N_MAX > 6) ? "yes":"no";
function fLDisplay(e){ e.innerHTML = "N_MAX is less than 2."; } function fGDisplay(e){ e.innerHTML = "N_MAX is greater than 2."; } function fLThan(sId){ let e = getElement(sId); let f = (N_MAX < 2) ? fLDisplay:fGDisplay; f(); }
Logical Operators
The following operators apply OR, AND or NOT, to two terms.
||, &&, !
Bitwise Operators
Bitwise operators return bit processes on two terms. The following operators apply bitwise OR, AND, NOT, XOR, left shift (zero fill), right shift (zero fill) and signed right shift.
See bitwise OR and AND results.
|, &, ~,^,<<, >>>, >>
Shifts
Shifts move bits to the left or right.
Zero fill
means that bit spaces, after a shift, are filled with zeros.
Signed
right shift means the sign bit fills vacated spaces.
The sign bit is one for negative numbers and zero for positive numbers.
See bit shift results.
<<, >>>, >>
String Method
String method
indexOf()
applies to
question seventeen, below.
Array Methods
The following built-in array methods return results below,
reduce(),filter(), forEach(), isArray()
and sort()
.
See array and string methods with results.
Math Methods
The following built-in math methods return results below,
Math.max(), Math.min(), Math.round(), Math.toFixed(), Math.sqrt(), Math.sin()
and Math.pow()
.
Also see math property Math.PI
.
See Math built-in methods with results.
Examples: JavaScript Results
The following boxes automatically display JavaScript code along with the result from processing the code. Boxes, code and results process and render with file solutions.js.
Variable Names
This section reuses generic variables
named x, y
and f
.
Generally it's best to apply variable names
which make their meaning clear.
Additionally functions are usually named
with verb-noun pairs.
However for this example, where variables have
multiple uses, I chose generic names.
Yet, no matter what the purpose, variable names must avoid
the use of keywords
Keywords
Keywords can not be used as variable or function names. Keywords are case sensitive.
Keywords include var, let, const,
if, switch, for, function, return
and
try
.
Keyword let
declares
a variable that's scoped within a block.
Keyword const
declares a constant. However, properties of
const
arrays and classes can change.
Keyword try
catches errors or exceptions
within a block.
Summary
You quickly learned about forty different JavaScript operators, keywords, built-in functions and other features with this simple section. JavaScript file, solutions.js processes and displays each example.
You learned about operators including
mathematical, comparison, type, ternary,
logical and bitwise operators.
You saw bit shifts, rounding, modulus operations,
functions, properties,
functions as properties, the typeof
operator, and
automatic type conversion.
You saw
built in functions such as
square root, power, sine, maximum, filter
and reducing.
You may also download and view the JavaScript file, solutions.js, which processes results for this page.
Learn JavaScript
JavaScript's the foundation of Web developer and Website design skills. This free and unique JavaScript tutorial includes some new or seldom used, but useful features.