Coding with JavaScript For Dummies
Book image
Explore Book Buy On Amazon
Master coding with JavaScript by discovering which words are reserved in JavaScript, an extensive list of HTML5 APIs, and jQuery selectors. Just check out these helpful tips to get started.

JavaScript reserved words

When coding with JavaScript, it will benefit you to know certain reserved words. The following list contains JavaScript reserved words. You can’t use these words as JavaScript variables, functions, methods, loop labels, or object names.

abstract final public
boolean finally return
break float short
byte for static
case function super
catch goto switch
char if synchronized
class implements this
const import throw
continue in throws
debugger instanceof transient
default int true
delete interface try
do long typeof
double native var
else new void
enum null volatile
export package while
extends private with
false protected

List of HTML5 APIs for coding with JavaScript

Here is an extensive list of HTML5 APIs that have either been proposed or implemented. Browsers are constantly being updated with new features. For the latest on which browsers support which features, visit caniuse.com.

API What It Does
Ambient Light API Provides information about the ambient light levels, as
detected by a device’s light sensor.
Battery Status API Provides information about the battery status of the
device.
Canvas 2D Context Allows drawing and manipulation of graphics in a browser.
Clipboard API Provides access to the operating system’s copy, cut, and
paste functionality.
Contacts Allows access to a user’s contacts repository in the web
browser.
Drag and Drop Supports dragging and dropping items within and between browser
windows.
File API Provides programs with secure access to the device’s file
system.
Forms Gives programs access to the new data types defined in
HTML5.
Fullscreen API Controls the use of the user’s full screen for web pages,
without the browser user interface.
Gamepad API Supports input from USB gamepad controllers.
Geolocation Provides web applications with access to geographical location
data about the user’s device.
getUserMedia/Stream API Provides access to external device data (such as webcam
video).
History API Allows programs to manipulate the browser history.
HTML Microdata Provides a way to annotate content with computer-readable
labels.
Indexed database Creates a simple client-side database system in the web
browser.
Internationalization API Provides access to locale-sensitive formatting and string
comparison.
Offline apps Allows programmers to make web apps available in offline
mode.
Proximity API Provides information about the distance between a device and an
object.
Screen Orientation Reads the screen orientation state (portrait or landscape) and
gives programmers the ability to know when it changes and to lock
it in place.
Selection Supports selecting elements in JavaScript using CSS-style
selectors.
Server-sent events Allows the server to push data to the browser without the
browser needing to request it.
User Timing API Gives programmers access to high-precision timestamps to
measure the performance of applications.
Vibration API Allows access to the vibration functionality of the
device.
Web Audio API API for processing and synthesizing audio.
Web Messaging Allows browser windows to communicate with each other across
different origins.
Web Speech API Provides speech input and text-to-speech output features.
Web storage Allows the storage of key-value pairs in the browser.
Web sockets Opens an interactive communication session between the browser
and server.
Web Workers Allows JavaScript to execute scripts in the background.
XMLHttpRequest2 Improves XMLHttpRequest to eliminate
the need to work around the same-origin policy errors and to make
XMLHttpRequest work with new features of
HTML5.

jQuery selectors for coding with JavaScript

JQuery provides many different ways to match sets of elements within a document beyond the methods built into JavaScript. Check out this list of all the jQuery selectors. To use them, simply pass them to the jQuery function (or, you can use the $ alias for the jQuery function). For example:

  • $(“*”) selects every element.

  • $(“div p:first-child”) selects the first paragraph child of each matched div element.

  • $(“div:contains(‘We hold these truths’)”) selects the divs that contain the matching text.

Check here to see examples of each of these jQuery selectors inside programs.

Selector What It Selects
All Selector (“*”) All elements.
:animated Selector All elements that are animated at the time of selection.
Attribute Contains Prefix Selector [name|=”value”] Elements that have the specified attribute with a value either
equal to a given string or starting with that string followed by a
hyphen (-).
Attribute Contains Selector [name*=”value”] Elements that have the specified attribute with a value
containing a given substring.
Attribute Contains Word Selector [name~=”value”] Elements that have the specified attribute with a value
containing a given word, delimited by spaces.
Attribute Ends With Selector [name$=”value”] Elements that have the specified attribute with a value ending
exactly with a given string. The comparison is case sensitive.
Attribute Equals Selector [name=”value”] Elements that have the specified attribute with a value exactly
equal to a certain value.
Attribute Not Equal Selector [name!=”value”] Elements that either don’t have the specified attribute
or do have the specified attribute but not with a certain
value.
Attribute Starts With Selector [name^=”value”] Elements that have the specified attribute with a value
beginning exactly with a given string.
:button Selector All button elements and elements of type button.
:checkbox Selector Elements of type checkbox.
:checked Selector All elements that are checked or selected.
Child Selector (“parent > child”) All direct child elements specified by “child” of
elements specified by “parent”.
Class Selector (“.class”) Elements with the given class.
:contains() Selector Elements that contain the specified text.
Descendant Selector (“ancestor descendant”) Elements that are descendants of a given ancestor.
:disabled Selector Elements that are disabled.
Element Selector (“element”) Elements with the given tag name.
:empty Selector Elements that have no children (including text nodes).
:enabled Selector Elements that are enabled.
:eq() Selector The element at index n within the matched set.
:even Selector Even elements, zero-indexed. See also odd.
:file Selector Elements of type file.
:first-child Selector Elements that are the first child of their parent.
:first-of-type Selector Elements that are the first among siblings of the same element
name.
:first Selector The first matched element.
:focus Selector The element that is currently focused.
:gt() Selector Elements at an index greater than index within the matched
set.
Has Attribute Selector [name] Elements that have the specified attribute, with any
value.
:has() Selector Elements which contain at least one element that matches the
specified selector.
:header Selector Elements that are headers, like h1, h2, h3, and so on.
:hidden Selector Elements that are hidden.
ID Selector (“#id”) A single element with the given id attribute.
:image Selector Elements of type image.
:input Selector All input, textarea, select, and button elements.
:lang() Selector Elements of the specified language.
:last-child Selector Elements that are the last child of their parent.
:last-of-type Selector Elements that are the last among siblings of the same element
name.
:last Selector The last matched element.
:lt() Selector Elements at an index less than index within the matched
set.
Multiple Attribute Selector [name=”value”][name2=”value2″] Elements that match all the specified attribute filters.
Multiple Selector (“selector1, selector2,
selectorN”)
The combined results of all the specified selectors.
Next Adjacent Selector (“prev + next”) All next elements matching “next” that are
immediately preceded by a sibling “prev”.
Next Siblings Selector (“prev ~ siblings”) All sibling elements that follow after the “prev”
element, have the same parent, and match the filtering
“siblings” selector.
:not() Selector Elements that do not match the given selector.
:nth-child() Selector Elements that are the nth-child of their parent.
:nth-last-child() Selector Elements that are the nth-child of their parent, counting from
the last element to the first.
:nth-last-of-type() Selector All the elements that are the nth-child of their parent in
relation to siblings with the same element name, counting from the
last element to the first.
:nth-of-type() Selector Elements that are the nth child of their parent in relation to
siblings with the same element name.
:odd Selector Odd elements, zero-indexed. See also even.
:only-child Selector Elements that are the only child of their parent.
:only-of-type Selector Elements that have no siblings with the same element name.
:parent Selector Elements that have at least one child node (either an element
or text).
:password Selector Elements of type password.
:radio Selector Elements of type radio.
:reset Selector Elements of type reset.
:root Selector The element that is the root of the document.
:selected Selector Elements that are selected.
:submit Selector Elements of type submit.
:target Selector The target element indicated by the fragment identifier of the
document’s URI.
:text Selector All input elements of type text.
:visible Selector Elements that are visible.

About This Article

This article is from the book:

About the book authors:

Chris Minnick is an accomplished author, trainer, and web developer who has worked on web and mobile projects for both small and major businesses. Eva Holland is an experienced writer and trainer who has designed and taught online, in-person, and video courses. They are cofounders of WatzThis?

This article can be found in the category: