Special symbols in javascript

JavaScript Special Characters

In JavaScript you can add special characters to a text string by using the backslash sign.

Insert Special Characters

The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.

Look at the following JavaScript code:

var txt="We are the so-called "Vikings" from the north."; document.write(txt);

In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called

To solve this problem, you must place a backslash (\) before each double quote in «Viking». This turns each double quote into a string literal:

var txt="We are the so-called \"Vikings\" from the north."; document.write(txt);

JavaScript will now output the proper text string: We are the so-called «Vikings» from the north.

The example above will produce the following output:

The table below lists other special characters that can be added to a text string with the backslash sign:

Code Outputs
\’ single quote
double quote
\& ampersand
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Your browser does not support inline frames or is currently configured not to display inline frames.

Make your web applications look like a million bucks

Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces «life» into the web applications by converting monotonous data into lively charts, gauges & maps.

FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc. and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our 12,000 customers and 150,000 users which include a majority of the Fortune 500 companies. And yeah, your applications could look like a million bucks by spending just $69.

So go ahead, download your copy of FusionCharts and start «wow-ing» your customers now!

W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user.
While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright 1999-2009 by Refsnes Data. All Rights Reserved.

Источник

Detailed Overview of Well-known Symbols

Post cover

Symbol is a new primitive type available from ECMAScript 2015, which allow to create unique identifiers let uniqueKey = Symbol(‘SymbolName’) .

You may use symbols as keys of properties in objects. A list of symbols that JavaScript treats specially is published as well-known symbols.
Well-known symbols are used by built-in JavaScript algorithms. For example Symbol.iterator is utilized to iterate over items in arrays, strings, or even to define your own iterator function.

These special symbols are important because they are system properties of objects that allow to define custom behavior. Sounds great, use them to hook into JavaScript!

Being unique, using symbols as keys (instead of string literals) allow easily to add new functionality to objects. You don’t have to worry about keys collision (because every symbol is unique), which can be a problem when using string literals.

This article guides through the list of well-known symbols and explains how to use them comfortable in your code.

Often for simplicity a well-known Symbol. is abbreviated to @@ format. For example Symbol.iterator is @@iterator or Symbol.toPrimitive is @@toPrimitive.
It’s possible to say that an object has an @@iterator method. It indicates that the object has a property named Symbol.iterator that holds a function:
< [Symbol.iterator]: function()<. >> .

Before I go on, let me recommend something to you.

The path to becoming good at JavaScript isn’t easy. but fortunately with a good teacher you can shortcut.

Take «Modern JavaScript From The Beginning 2.0» course by Brad Traversy to become proficient in JavaScript in just a few weeks. Use the coupon code DMITRI and get your 20% discount!

1. A short introduction to Symbol

Symbol is a primitive type (like numbers, booleans and strings), unique and immutable.

To create a symbol, invoke Symbol function with an optional name argument:

Источник

Читайте также:  Python stop running script
Оцените статью