Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære JavaScript Operators | JavaScript syntax
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
JavaScript Operators

We use operators to perfor some actions on the operands. Operands can be variables, numeric literals, or string literals.

JavaScript Operators Syntax:

We can use the operators between two or more operands to perform a specific task.

12345678910111213141516171819
// (numerical operator) const sum = 45 + 2; console.log(sum); // (bitwise operator) const value = 5 | 1; console.log(value); // (logical operator) const isRaining = true; console.log(isRaining); //(assignment opearator) const number = 5; console.log(number); // (relational operator) const isLess = 45 == 10; console.log(isLess);
copy

Description of above code

  1. Numerical operators usually perform some numerical actions on the variable.
  2. Bitwise operators treat their operands as a set of 32-bit binary digits (zeros and ones) and perform actions.
  3. The logical operator returns true or false based on condition.
  4. We use assignment operators to assign values to the variable.
  5. Relational operators are for checking the relation between operands.

Note:

The complete detail of operators will be discussed later in the course.

Opgave

Swipe to start coding

Create three variables named firstItem, secondItem, and difference. Assign the values 50 and 20 to firstItem and secondItem respectively. Find the difference and assign the value to the difference variable and display it.

Løsning

Summary:

  • The syntax is a set of rules which defines a program is true or not.
  • JavaScript has two types of values: literals and variables.
  • Literals cannot be can not change the code and we do not specify any keywords.
  • Variables are used to store data. They are declared with name (which is not a keyword) and usually initialized with a value.
  • Operators are used to perform some actions.
  • JavaScript operators are used to perform special operations.

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 2. Kapitel 3
toggle bottom row

book
JavaScript Operators

We use operators to perfor some actions on the operands. Operands can be variables, numeric literals, or string literals.

JavaScript Operators Syntax:

We can use the operators between two or more operands to perform a specific task.

12345678910111213141516171819
// (numerical operator) const sum = 45 + 2; console.log(sum); // (bitwise operator) const value = 5 | 1; console.log(value); // (logical operator) const isRaining = true; console.log(isRaining); //(assignment opearator) const number = 5; console.log(number); // (relational operator) const isLess = 45 == 10; console.log(isLess);
copy

Description of above code

  1. Numerical operators usually perform some numerical actions on the variable.
  2. Bitwise operators treat their operands as a set of 32-bit binary digits (zeros and ones) and perform actions.
  3. The logical operator returns true or false based on condition.
  4. We use assignment operators to assign values to the variable.
  5. Relational operators are for checking the relation between operands.

Note:

The complete detail of operators will be discussed later in the course.

Opgave

Swipe to start coding

Create three variables named firstItem, secondItem, and difference. Assign the values 50 and 20 to firstItem and secondItem respectively. Find the difference and assign the value to the difference variable and display it.

Løsning

Summary:

  • The syntax is a set of rules which defines a program is true or not.
  • JavaScript has two types of values: literals and variables.
  • Literals cannot be can not change the code and we do not specify any keywords.
  • Variables are used to store data. They are declared with name (which is not a keyword) and usually initialized with a value.
  • Operators are used to perform some actions.
  • JavaScript operators are used to perform special operations.

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 2. Kapitel 3
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