By: aathishankaran in JavaScript Tutorials on 2007年03月29日 [フレーム]
In JavaScript, the substring() method is used to extract a portion of a string. It takes two parameters: the starting index and the ending index of the substring. Here's an example:
const str = "Hello, world!"; const subStr = str.substring(0, 5); // "Hello"
In the example above, the substring() method is used to extract the first five characters of the string.
Formatted strings, also known as template literals, allow for easy string interpolation and formatting. They use the backtick (`) character to define the string and allow for placeholders, which are denoted by a dollar sign followed by curly braces (${expression}). Here's an example:
const name = "Alice";
const age = 25;
const formattedString = `My name is ${name} and I am ${age} years old.`;
console.log(formattedString); // "My name is Alice and I am 25 years old."
In the example above, the formattedString variable is defined using a template literal, with placeholders for the name and age variables. When the string is logged to the console, the placeholders are replaced with their corresponding values.
Keep in mind the context in which you can use the formatting methods. You cannot use them outside a JavaScript script as a substitute for HTML formatting tags.
anchor("anchorName")
"Section3".anchor
<A NAME="Section3">Section('Section3")3</A>
big()
"Just save the name".big()
<BIG>Just save the name</BIG>
Blink()
"Why ask why".blink()
<BLlNK>Why ask why</BLlNK>
Boid()
"Liveandlearn".bold()
<B>Liveandlearn</B>
Fixed()
"JavaScriptcode".fixed()
<TT>JavaScript code</TT>
fontcolor("color")
"JavaPrograms".fontcolor("green")
<FONTCOLOR"green">JavaPrgrams</FONT>
fontsize(size)
"Impact".fontsize(3)
<FONT SIZE="3">lmpact</FONT>
Italics()
"Java Script Unleashed".italics()
<I>JavaScript Unleashed</I>
Link("URL")
"See My Home Page". link("http://www.myhomepage.com/")
<A HREF="http//www.myhomepage.com/> SeeMyHomePage</A>
Small()
"TinyTim".small()
<SMALL>Tiny Tim</SMALL>
Strike()
"GameCanceled"strike()
<STRIKE>GameCanceled</STRIKE>
Sub()
"Submarines".sub()
<SUB>Submarines</SUB>
sup()
"Superman".sup()
<SUP>Superman</SUP>
toLowerCase()
"SeeSPOTrUN".toLowerCase()
seespotrun
ToUpperCase()
"let's go to the BEACH".toUpperCase()
LET'S GO TO THE BEACH
Working with Special Characters
When working with strings in any language, you will discover certain characters that are difficult to use. JavaScript enables you to work with these special case characters by using a backslash character (\) followed by the character or its code. Table below lists the JavaScript in line symbols.
Symbol
Description
\t
Tab
\n
New line
\r
Carriage return
\f
Form feed
\\
Backslash
\b
Backspace
\"
Double quote
\'
Single quote
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JavaScript )
Dynamically modify the option set in Dynamics 365 forms
promise and .then() in JavaScript
reduce() and filter() in JavaScript
History and evolution of Javascript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Show how many characters remaining in a html text box using javascript
Latest Articles (in JavaScript)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate