GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript-notes/06-types-string.md at master · geekysrm/javascript-notes

Expand file tree

/

06-types-string.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
98 lines (61 loc) · 2.04 KB
/

06-types-string.md

Copy path

File metadata and controls

98 lines (61 loc) · 2.04 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

String

  • used for holding text

  • 3 ways to create strings:

    1. using single quotes:

      const first = 'Soumya';

    2. using double quotes:

      const middle = "Ranjan";

    3. using backticks:

       	const last = `Mohanty`;
  • single quotes and double quotes are the same thing.

    used for: "she's cool"

    or escaping: 'she\\'s cool'

  • backticks:

      const sentence = `she's so "cool"`;
      console.log(sentence); // she's so "cool"
  • Multi-line string:

      const song = 'Oh \\
      I like \\
      pizza';
      
      console.log(song); // Oh I like pizza
      const song = `Oh
      I like
      pizza`;
      
      console.log(song); 
      /*
      Oh
      I like
      pizza
      */

    2nd one using backticks is mostly used.

  • String concatenation and interpolation

    • '+' is used for concatenation. It is also used for adding 2 nos.
    • Concatenation: when 2 or more strings combined to one
    • Interpolation: when you put a variable inside a string
    • Example 1:

    const name = 'Soumya';

    const hello = 'Hello my name is ' + name + '. Nice to meet you.'

    (can use double or single quotes)

    • Example 2:

    1+1 // 2

    '1'+'1' // 11

    1 + '1' // 11

    • Example 3:

      const name = 'Soumya'; const hello = Hello my name is ${name}. Nice to meet you. I am ${100+1} years old.; console.log(hello); // Hello my name is Soumya. Nice to meet you. I am 101 years old.

    • Backticks also used for tagged template literals.

    • Backticks are helpful for creating HTML:

        const html = `
        	<div>
        		<h2>Hey everyone! I am ${name}.</h2>
        	</div>
        `;
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.