Values | JavaScript | Pedro Lara

Código, Libros y Podcast

Values | JavaScript | Pedro Lara

No hay comentarios


In JavaScript, there are several types of values, including:

Numbers: Numeric values can be integers or decimals. Examples of numbers are 1, 3.14, -7, etc.

let decimal:number= 7;
let age = 25;
let pi = 3.14159;
let negativeNumber = -10;

Strings: Textual values enclosed in single or double quotes. Examples of strings are "hello", 'world', "123", etc.

let firstName = "John";
let lastName = 'Doe';
let greeting = "Hello, my name is " + firstName + " " + lastName;

Booleans: Logical values that can be either true or false.


let isTrue = true;
let isFalse = false;
let isEqual = (2 + 2 == 4); //true

          


Undefined: A variable that has been declared but not assigned a value is undefined.


let notDefined;
console.log(notDefined); //undefined

          


Null: Represents the intentional absence of any object value.


let noValue = null;

          


Objects: A collection of key-value pairs, where the key is a string and the value can be any other data type.


let person = { name: "Alice", age: 30, city: "New York" };

          


Arrays: An ordered collection of values, where each value can be of any data type.


let fruits = ["apple", "banana", "orange"];

          


Symbols: Unique and immutable data type that can be used as an identifier for object properties.

    let sym1 = Symbol();
let sym2 = Symbol("foo");
    


Null: Represents the intentional absence of any object value.


let fruits = ["apple", "banana", "orange"];

          


Functions: Functions are a special type of object that can be invoked with arguments.

function addNumbers(a, b) {
  return a + b;
}
          


BigInt: A built-in object used for representing integers with arbitrary precision.


let largeNumber = 9007199254740991n;       

These data types in JavaScript are important to understand because they determine the operations that can be performed on them and the results that can be expected.


No hay comentarios :

Publicar un comentario