Notice: Undefined variable: user_id in /home/thetexvn/domains/thetexvn.com/public_html/blogs/follow.php on line 40
Comments, Escape Sequence, and Built-in Functions in JavaScript | by Zia | TEXVN

Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0


advertisement

Comments, Escape Sequence, and Built-in Functions in JavaScript

built-in functions in javascript

Using comments

A Web page designer might code complex scripts to fulfill a specific task. In JavaScript, a Web page designer specifies comments to provide information about a piece of code in the script. Comments describe the code in simple words so that somebody who reads the code can understand the code. Comments are a small piece of text that makes the program more readable. While the script is executed, the browser can identify comments as they are marked with special characters and do not display them.

JavaScript supports two types of comment. These are as follows:

Single-line comments

Single-line comments begin with two forward slashes (//).

You can insert single-line comments as follows:

// This statement declares a variable named num.
var num;


Multi-line comments

Multi-line comments begin with a forward slash followed by an asterisk (/*) and end with an asterisk followed by a forward slash (*/). You can insert multiple lines of comments as follows:

/* This line of code
declares a variable */
var num;


Escape sequence characters

An escape sequence character is a special character that is preceded by a backslash (\). Escape sequence characters are used to display special non-printing characters such as a tab space, a single space, or a backspace. These non-printing characters help in displaying formatted output to the user to maximize readability. The backslash character specifies that the following character denotes a non-printing character. For example, \t is an escape sequence character that inserts a tab space similar to the Tab key on the keyboard. The escape sequence characters in JavaScript must always be enclosed in double quotes.

Multiple escape sequence characters in JavaScript provide various kinds of formatting.

Lists the escape sequence characters.

  • \b: Backspace
  • \f: Form feed
  • \n: New line
  • \r: Carriage return
  • \t: Horizontal tab
  • \': Single quote
  • \": Double quote
  • \\: Backslash
  • \aaa: Matches a Latin-1 encoded character using an octal representation, where aaa is three octal numbers. For example, \251 represents the copyright symbol
  • \xaa: Matches a Latin-1 encoded character using hexadecimal representation, where aa is two hexadecimal numbers. For example, \X61 represents the character 'a'
  • \uaaaa: Represent the Unicode encoding character, where aaaa is four hexadecimal numbers. For example, the character \u0020 represents a space

The use of escape sequence characters in JavaScript.

<script>
document.write ("You must have a \u0022 credit card \u0022, if you want to shop on the \'Internet\'."):
</script>

The code uses a Unicode encoding character namely, \u0022, which represents double quotes. These open and closed double quotes will contain the term credit card. Similarly, the word Internet will be placed in single quotes. The single quotes are specified using the backslash character.

Note - An encoding scheme specifies how to represent character data in terms of their acceptable range, maximum number of characters, and patterns. Unicode is a character set that contains all the international characters required for processing information. Latin 1 is the encoding scheme for English and Western European languages on the Internet.


Built-in Functions

A function is a piece of code that performs some operations on variables to fulfill a specific task. It takes one or more input values, processes them, and returns an output value. JavaScript provides built-in functions that are already defined to fulfill a certain task.

Lists the built-in functions.

  • alert(): Displays a dialog box with some information and an OK button

  • confirm(): Displays a dialog box with OK and Cancel buttons. It verifies an action that a user wants to perform

  • parseInt(): Converts a string value into a numeric value

  • parseFloat(): Converts a string value into a decimal point

  • eval(): Evaluates an expression and returns the evaluated result

  • isNaN(): Checks whether a value is not a numbered

  • prompt(): Displays a dialog box that accepts prompt input value through a text box. It also accepts the default value for the text box.


Note - The \n character, when used in the alert () function, prints the information on a new line. This does not happen when the \n character is used with the write method of the document object.
The use of some of the built-in functions in JavaScript. It performs additional operations using JavaScript.


<!DOCTYPE HTML>
<html>
<head>
<title> JavaScript language </title>
<script>
var value = "";
var numone= prompt ("enter first value to perform the multiplication operation", value);
var numtwo = prompt ("enter second value to perform the multiplication operation", value);
var result = eval(numone * numtwo);
document.write("The result of multiplying: " + numone + " and " + numtwo + " is: " + result + "." );
</script>
</head>
</html>

In the code, it takes the first value from the user and stores it in the numOne variable. Then, it takes the second value from the user and stores it in the numtwo variable. It multiplies the values stores the output in the result variable and then displays the output on the Web page.


JavaScript Comments in JavaScript Built in Functions Escape Sequence in JavaScript Escape Sequence Characters Built in functions in javascript using comments in javascript Single Line comments multi line comments

advertisement


Profile Image

Published by: 

1 Follower

Zia, founder and CEO of Texvn and Toolx, is a passionate entrepreneur and tech enthusiast. With a strong focus on empowering developers, he creates innovative tools and content, making coding and idea generation easier.