JS Methods and Functions, JS Escape Sequence

0 60

JS Methods and Functions JS Escape Sequence

in this tutorial, we will briefly discuss JS Methods and Functions JS Escape Sequence.

Methods in JavaScript

Methods of document object allow a user to display information in JavaScript. A document object is a predefined object in JavaScript which allows managing page dynamically in the html page. In javascript, each object consists of methods to perform a specific task. Two type methods of a document object there to display any type’s data in a browser.

write(); Displays any type of data in a browser.

writeln(); Displays any type of data and appends a new line character.

Functions

Functions are the code of block to perform specific action on most variable to perform the specific tasks.The function takes one or more values processes them according to requirement and returns an output value.

JavaScript defined some built-in functions to perform task.

Function Description Example
alert() shows a dialog box with information and OK button alert("Please fill all the required fields in form");
confirm() Displays a confirm dialog box confirm("Are you sure you want to close the page?");
parseInt() Converts a string value into a numeric value arseInt("35 years");
parseFloat() Converts a string into a number with decimal point parseFloat("15.89"); ;
eval() Evaluates an expression and returns the evaluated result eval("4+6");
isNaN() Checks whether a value is not a number isNan("Hi");
prompt() shows a dialog box that accepts an input value through a text box. prompt("Enter your age" "Age");

JS Escape Sequence

Escape Sequence Characters in JavaScript

Escape Sequence Characters are special characters that are starting with backslash
These characters are used to display non printing characters such as backspace tab space or a new line. Escape sequence character displaying formatted output to the user to maximize readability escape sequence characters must always be enclosed in double quotes.

There is multiple escape sequence character to provide various kind of formatting.

Escape Sequence Non-Printing Character
b Backspace
f Form feed
n new line
r Carriage return
t Horizontal tab
' Single quote
\ Backslash
aaa Matches a Latin-1 encoding character using octal representation where aaa are three octal numbers. For example 251 represents the copyright symbol
xaa Matches a Latin-1 encoding character using hexadecimal representation where aa are two hexadecimal numbers. For example x61 represents the character 'a'
uaaaa Represent the Unicode encoding character where aaaa are four hexadecimal numbers. For example the character u0020 represents a space

Comments

comments

Leave A Reply

Your email address will not be published.