Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Data Types Overview | Variables and Data Types
Introduction to JavaScript
course content

Conteúdo do Curso

Introduction to JavaScript

Introduction to JavaScript

1. Basic Concepts
2. Variables and Data Types
3. Basic Operations
4. Conditional Statements
5. Loops
6. Functions

bookData Types Overview

Data can be represented in various ways, and the operations you perform on data can differ depending on the data types.

Note

The Data Type tells the interpreter how to work with the data.

Let's look at the difference in the interpreter behavior:

12345
// First case console.log("123" + "123"); // Second case console.log(123 + 123);
copy

In the example above, you can see that the interpreter performs different operations for different data types.

typeof()

The typeof() operator returns a string indicating the type of the operand's value.

1234567
let a = 15; console.log(typeof 23); console.log(typeof a); const b = "today"; console.log(typeof "word"); console.log(typeof b);
copy

Number

The number data type is used for calculations, counters, mathematical operations, and more.

Unlike other programming languages, JavaScript uses the number type instead of separate int and float types.

12345
console.log(typeof(15.25)); console.log(typeof(211)); console.log(typeof(22 + 251)); console.log(typeof(26 / 342));
copy

Note

The typeof operator only determines the data type of the result, not the performed operations.

String

The string data type is used to change, print, and pass text to other programs.

12
let str = "Hello! I'm String, and I should help you to work with text!"; console.log(str);
copy

To identify the string in the code, we should use single or double quotes (e.g., 'some text' or "some text")

1234567
console.log("text"); console.log('text'); console.log("console.log('text')"); console.log('console.log("text")'); console.log(typeof("10"));
copy

Note

  • Choose one quote style ("text" or 'text') for your code or project;
  • You can switch between quote styles when using ' or " within the text, such as "She hasn't hat" or 'He says "Hi!"'.

Boolean

The boolean data type is used for logical operations. It has two values: true and false. Booleans are used to check conditions, as we'll describe later.

Booleans allow you to control code execution and direct it along different paths.

To create a boolean value, use the true or false values:

12345678
console.log(true); console.log(false); console.log(typeof(true)); console.log(typeof(false)); console.log(25 > 15); console.log(15 > 25);
copy
1. The `true` and `false` are ___.
2. What is the data type of the value `"number"`?
3. What is the data type of the value `15`?
4. What is the data type of the value `19.32`?
5. What is the data type of the value `true`?
6. Drag values to their types.
 The `true` and `false` are ___.

The true and false are ___.

Selecione a resposta correta

What is the data type of the value `"number"`?

What is the data type of the value "number"?

Selecione a resposta correta

What is the data type of the value `15`?

What is the data type of the value 15?

Selecione a resposta correta

What is the data type of the value `19.32`?

What is the data type of the value 19.32?

Selecione a resposta correta

What is the data type of the value `true`?

What is the data type of the value true?

Selecione a resposta correta

question-icon

Drag values to their types.

string:

number:


boolean:

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
some-alt