3D Gallery with Great Artwork Imagine Logo with Three Colors Beach Cabin 3D Android Tablet with Different Screens Studio Apartment Red Figured Greek Vase on Blue Background Silver and Gold Flashlight Lake on Fire

JavaScript: Feature Range

Page 3

Feature Range

Introduction Operators Examples: JavaScript Results: Post Decrement, Pre Increment Bit Shift Left Signed Bit Shift Right Binary OR Binary AND Index Of Object Property Object with Function Math.sin() Variable Names See Code: solutions.js Summary

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.

Tags
canvas drawing, web design, web designing course, how to become a web developer, coding websites, website developers,learning web design, html web design, html5 canvas tutorials, coding Website, html5 canvas, learn to code, html5 canvas tutorial,learn html tutorial, simple html tutorial

Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1

for Web graphics!

Copyright © 2022 Amy Butler. All Rights Reserved.