Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Strings 1/5 | Data Types and Variables
Introduction to JavaScript (staging)
course content

Kursusindhold

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

1. Introduction
2. JavaScript syntax
3. Data Types and Variables

book
Strings 1/5

What are Strings

A primitive data type is used to deal with textual data. String, in programming, is one of the data types and it can be used to store all those types of information that we usually write in plain English. For example address of a place is written in plain English, email address, name of a person, etc.
A string is a sequence of characters and a character is simply a symbol. For example, the English language has 26 characters (a to z).

Backticks in JavaScript

Practically single quotes and double quotes are the same as we learned earlier. But backticks are more versatile and they gave us the ability to embed the expression within the strings by using${…}. Expression is the code snippet that returns some value.

1
console.log(`1 + 2 = ${1+2}`);
copy

As you can see in the above code, the backticks have been used along with the ${} to evaluate an expression.

Another advantage of backticks is that we can span our strings across multiple lines naturally.

12345
let guestList = `Guests: * John * * Pete * * Mary *`; console.log(guestList);
copy
Opgave

Swipe to start coding

A string variable named multiplication with the assigned value of 6 * 2 has been given to you. Your task is to change the declaration of the above variable with backticks and the ${} to evaluate the expression in such a way that the output should look like this. 6*2 = 12

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 19
toggle bottom row

book
Strings 1/5

What are Strings

A primitive data type is used to deal with textual data. String, in programming, is one of the data types and it can be used to store all those types of information that we usually write in plain English. For example address of a place is written in plain English, email address, name of a person, etc.
A string is a sequence of characters and a character is simply a symbol. For example, the English language has 26 characters (a to z).

Backticks in JavaScript

Practically single quotes and double quotes are the same as we learned earlier. But backticks are more versatile and they gave us the ability to embed the expression within the strings by using${…}. Expression is the code snippet that returns some value.

1
console.log(`1 + 2 = ${1+2}`);
copy

As you can see in the above code, the backticks have been used along with the ${} to evaluate an expression.

Another advantage of backticks is that we can span our strings across multiple lines naturally.

12345
let guestList = `Guests: * John * * Pete * * Mary *`; console.log(guestList);
copy
Opgave

Swipe to start coding

A string variable named multiplication with the assigned value of 6 * 2 has been given to you. Your task is to change the declaration of the above variable with backticks and the ${} to evaluate the expression in such a way that the output should look like this. 6*2 = 12

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 19
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt