Skip to main content

Exercise 8: Verifying Data Types with JavaScript

Explore how to identify different data types in JavaScript. This tutorial guides you through the use of typeof and its utility in data validation.

The main objective is to learn how to identify data types in JavaScript using the typeof operator.

Activity

  1. Declare three variables namededad,nombre, and esEstudiante2. Assign values to the variables, using a number foredad, a text (string) fornombre, and a Boolean value (true either false) for esEstudiante3. Useconsole.logto display the type of each variable in the console usingtypeof

Solution

Step 1: Create the index.html file

HTML
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Verificando Tipos de Datos</title>
</head>
<body>
<h1>Ejercicio 8: Verificando Tipos de Datos</h1>
<p>Los cambios se muestran en consola.</p>
<script src="script.js"></script>
</body>
</html>

Step 2: Write the code in script.js

JavaScript
// Declaración de variables de diferentes tipos de datos
let edad = 25; // Número
let nombre = "Carlos"; // String (texto)
let esEstudiante = true; // Booleano

// Mostrar el tipo de cada variable en la consola
console.log("El tipo de 'edad' es: " + typeof edad); // number
console.log("El tipo de 'nombre' es: " + typeof nombre); // string
console.log("El tipo de 'esEstudiante' es: " + typeof esEstudiante); // boolean
info

🔎Check the sectionData Types in JavaScript: A Complete Guide with Practical Exampleswhere you will find more information on this topic.