lunes, 4 de mayo de 2015

JavaScript - Objeto String

Normalmente, las cadenas de JavaScript son valores primitivos, creados a partir de literales: var firstName = "Juan"
Pero las cadenas también pueden ser definidos como objetos con la palabra clave new: var firstName = new String ("Juan")

var x = "John";
var y = new String("John");
// typeof x retorna un string
// typeof y retorna un objet

Crear cadenas como objetos ralentiza la velocidad de ejecución  

Cuando se utiliza el operador de igualdad ==, los string se ven igual

var x = "John";             
var y = new String("John");
// (x == y) is true because x and y have equal values

Cuando se utiliza el operador de igualdad ===, los string no son iguales, porque el operador === espera la igualdad tanto en tipo y valor.

var x = "John";             
var y = new String("John");
// (x === y) is false because x and y have different types

Los objetos no se pueden comparar:

var x = new String("John");             
var y = new String("John");
// (x == y) is false because objects cannot be compared

Propiedades String


No hay comentarios:

Publicar un comentario