JAVASCRIPT Displays data
JavaScript can output data in different ways:
- Use the window.alert () pop- up warning box.
- Use the document.write () method to write content to an HTML document.
- Writes to an HTML element using InnerHTML .
- Use Console.log () to write to the browser's console
JavaScript Statement identifiers
JavaScript statements typically begin with a statement identifier and execute the statement.
Statement identifiers are reserved keywords that cannot be used as variable names.
The following table lists the JavaScript statement identifiers (keywords):
Statement |
Description |
Break |
Used to jump out of a loop. |
Catch |
Statement block that executes a catch statement block when a try statement block performs an error. |
Continue |
Skips an iteration in the loop. |
Do ... while |
Executes a block of statements that continues executing the statement block when the condition statement is true. |
For |
When the conditional statement is true, the code block can be executed a specified number of times. |
For ... in |
Used to iterate over an array or an object's properties (to iterate over a group or an object's properties). |
function |
Define a function |
If ... else |
Used to perform different actions based on different conditions. |
Return |
Exit function |
Switch |
Used to perform different actions based on different conditions. |
Throw |
Throws (generates) an error. |
Try |
Implements error handling and is used with catch. |
Var |
Declares a variable. |
While |
When the conditional statement is true, the statement block is executed. |
String method
Method |
Description |
CharAt () |
Returns the character of the specified index position |
charCodeAt () |
Returns the Unicode value of the specified index position character |
Concat () |
Concatenate two or more strings, returning the concatenated string |
fromCharCode () |
Convert Unicode to a string |
IndexOf () |
Retrieves the position of the first occurrence of the specified character in a string |
LastIndexOf () |
Retrieves the position of the last occurrence of the specified character in a string |
Localecompare () |
Compare two strings in a local-specific order |
Match () |
Found a match for one or more regular expressions |
Replace () |
To replace a substring that matches a regular expression |
Search () |
Retrieving a value that matches a regular expression |
Slice () |
Extracts a fragment of a string and returns the extracted part in a new string |
Split () |
To split a string into a substring array |
SUBSTR () |
Extracts a specified number of characters from the starting index number in a string |
SUBSTRING () |
Extracts the characters between two specified index numbers in a string |
toLocaleLowerCase () |
Converts a string to lowercase based on the host's locale, with only a few languages (such as Turkish) with a local case-specific mapping |
toLocaleUpperCase () |
Converts a string to uppercase based on the host's locale, with only a few languages (such as Turkish) with a local case-specific mapping |
toLowerCase () |
Convert a string to lowercase |
ToString () |
Returns the String object value |
toUpperCase () |
Convert a string to uppercase |
Trim () |
Remove string end and end blanks |
ValueOf () |
Returns the original value of a string object |
Regular expression modifiers
modifiers can be case insensitive in global search:
modifier |
Description |
I |
Performs a match that is not case sensitive. |
G |
Performs a global match (finds all matches rather than stops after the first match is found). |
M |
Performs multi-line matching. |
Regular expression pattern
Square brackets are used to find characters in a range:
An expression |
Description |
[ABC] |
Look for any characters between square brackets. |
[0-9] |
Look for any number from 0 to 9. |
(x|y) |
Find anything to | Delimited options. |
Metacharacters are characters that have special meanings:
Meta character |
Description |
\d |
Find numbers. |
\s |
Find white space characters. |
\b |
Matches the word boundary. |
\uxxxx |
Finds the Unicode characters specified in hexadecimal number xxxx. |
Quantifiers:
quantifier |
Description |
n+ |
Matches any string that contains at least one n . |
N |
Matches any string that contains 0 or more n . |
N? |
Matches any string that contains 0 or one n . |
Window Object Properties
Properties |
Description |
Closed |
Returns whether the window has been closed. |
Defaultstatus |
Sets or returns the default text in the window's status bar. |
Document |
A read-only reference to the Document object. (See objects) |
Frames |
Returns all named frames in the window. The collection is an array of window objects, each of which contains a frame in the windows. |
History |
A read-only reference to the History object. Please use the parameter history object. |
Innerheight |
Returns the height of the window's document display area. |
Innerwidth |
Returns the width of the window's document display area. |
Length |
Sets or returns the number of frames in a window. |
Location |
The location object used for the window or frame. See Location object. |
Name |
Sets or returns the name of the window. |
Navigator |
A read-only reference to the Navigator object. Please parameter Navigator object. |
Opener |
Returns a reference to the window that created this window. |
Outerheight |
Returns the outer height of the window, containing the toolbar and scroll bar. |
Outerwidth |
Returns the outer width of the window, including the toolbar and scroll bar. |
Pagexoffset |
Sets or returns the X position of the current page relative to the upper-left corner of the window display area. |
pageYOffset |
Sets or returns the Y position of the current page relative to the upper-left corner of the window display area. |
Parent |
Returns the parent window. |
Screen |
A read-only reference to the Screen object. Please parameter screen object. |
Screenleft |
Returns the x-coordinate relative to the screen window |
Screentop |
Returns the y-coordinate relative to the screen window |
ScreenX |
Returns the x-coordinate relative to the screen window |
ScreenY |
Returns the y-coordinate relative to the screen window |
Self |
Returns a reference to the current window. Equivalent to the Window property. |
Status |
Sets the text of the window's status bar. |
Top |
Returns the topmost parent window. |
Window Object method
Method |
Description |
Alert () |
Displays a warning box with a message and a confirmation button. |
Blur () |
Move the keyboard focus away from the top-level window. |
Clearinterval () |
Cancels the timeout set by SetInterval (). |
Cleartimeout () |
Cancels the timeout set by the SetTimeout () method. |
Close () |
Close the browser window. |
Confirm () |
Displays a dialog box with a message and a confirmation button and a Cancel button. |
Createpopup () |
Create a pop-up window. |
Focus () |
Give the keyboard focus to a window. |
Moveby () |
The specified pixel can be moved relative to the current coordinates of the window. |
MoveTo () |
Moves the upper-left corner of the window to a specified coordinate. |
Open () |
Open a new browser window or look for a named window. |
Print () |
Prints the contents of the current window. |
Prompt () |
Displays a dialog box to prompt the user for input. |
Resizeby () |
Resizes the window by the specified pixels. |
Resizeto () |
Adjusts the size of the window to the specified width and height. |
Scroll () |
|
Scrollby () |
Scrolls the content by the specified pixel value. |
ScrollTo () |
Scrolls the content to the specified coordinates. |
SetInterval () |
Invokes a function or evaluates an expression by the specified period (in milliseconds). |
SetTimeout () |
Invokes a function or evaluates an expression after the specified number of milliseconds. |
JS, JQ Intensive Review