Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Типи Даних та Базові Операції | Section
Основи JavaScript

bookТипи Даних та Базові Операції

Свайпніть щоб показати меню

JavaScript stores different kinds of data using data types. The main ones are:

  • String: text;
  • Number: numeric values;
  • Boolean: true / false;
  • Null: intentional empty value;
  • Undefined: not assigned.
12345678910111213
// Assigning different data types to variables let userName = "Alice"; // string let userAge = 30; // number let isMember = true; // boolean let middleName = null; // null let address; // undefined console.log(userName); // Output: Alice console.log(userAge); // Output: 30 console.log(isMember); // Output: true console.log(middleName); // Output: null console.log(address); // Output: undefined
copy

You can perform various basic operations with these data types. With numbers, you can use addition (+), subtraction (-), multiplication (*), and division (/).

With strings, the + operator is used for concatenation, meaning joining two or more strings together. JavaScript sometimes automatically converts one data type to another when performing operations—this is called type coercion. For example, adding a string and a number results in a string because JavaScript converts the number to a string.

12345678910111213141516171819
// Basic operations let a = 10; let b = 5; let sum = a + b; // Addition: 15 let difference = a - b; // Subtraction: 5 let greeting = "Hello, "; let name = "Bob"; let welcomeMessage = greeting + name; // Concatenation: "Hello, Bob" let result = "Age: " + 25; // Type coercion: "Age: 25" let mixed = 5 + "5"; // Type coercion: "55" console.log(sum); // Output: 15 console.log(difference); // Output: 5 console.log(welcomeMessage); // Output: Hello, Bob console.log(result); // Output: Age: 25 console.log(mixed); // Output: 55
copy
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 4
some-alt