Forem

Cover image for Objetos
ananopaisdojavascript
ananopaisdojavascript

Posted on

1

Objetos

Definição

Objetos são "super variáveis" que guardam uma chave (propriedade) e um valor. O objeto apareceu no minha primeira publicação (Tipos de Dados Primitivos), que vou deixar o link aqui.


let carro = {
        modelo: 'gol',
        cor: 'vermelho',
        acelerar(){
            console.log('Acelerando...');
        },
        frear(){
            console.log('Freando');
        },
};
Enter fullscreen mode Exit fullscreen mode

Acessando as propriedades

Podemos acessar as propriedades de um objeto por ponto ou por colchetes.

Notação de ponto

carro.modelo
Enter fullscreen mode Exit fullscreen mode

Notação de colchetes

carro['modelo']
Enter fullscreen mode Exit fullscreen mode

Alterar o valor de uma propriedade

Podemos alterar o valor de uma propriedade, usamos o operador de atribuição =.

carro.modelo = 'brasilia';
Enter fullscreen mode Exit fullscreen mode

Adicionar uma nova propriedade

Podemos também incluir uma nova propriedade ao objeto.

carro.ano = '1980';
console.log(carro['ano']);
Enter fullscreen mode Exit fullscreen mode

Excluir uma propriedade

Podemos também excluir uma propriedade com o operador delete.

delete carro.ano;
Enter fullscreen mode Exit fullscreen mode

E aí? Gostaram? Até a próxima anotação! 😊

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay