Urgent.News

What's breaking now, across thousands of outlets.

Tech

Objects in JS

Object is a non primitive data type to store functions and values. Multiple values as key:value pairs. Functions are stored as key:function() pairs called methods. Object store related information about one thing. Examples: let person = { name : " Priya " , age : 20 , city : " Chennai " }; console . log ( person ); output: {name: "Priya", age: 20, city: "Chennai"} To access object: Dot notation…

An object in JavaScript is a non-primitive data type used to store both functions and values through key-value pairs. Functions within an object take the form of key:function() pairs, known as methods. Objects are designed to encapsulate related information pertaining to a single entity. For instance, let person = { name: 'Priya', age: 20, city: 'Chennai' }; console.log(person); produces the output: {name: 'Priya', age: 20, city: 'Chennai'}.

Accessing an object's properties can be done using either dot notation or bracket notation. For example, console.log(person.name); and console.log(person.age); would output 'Priya' and 20 respectively. Additionally, to access a property stored as a value within an object, such as 'city', one would use console.log(person.city);, resulting in 'Chennai'.

Creating, reading, updating, and deleting (CRUD) operations can be performed on objects. To add a new property, let mobile = { name: 'Vivo', price: 20000 }; mobile.model = 'V80';; console.log(student); would output 'Vivo 20000 V80'. To read a property, console.log(mobile.name); would return 'Vivo', and console.log(mobile['name']); would also return 'Vivo'.

To update a property, mobile.price = 25000; would change the value to 25000, and console.log(mobile.price); would output 25000. Finally, to delete a property, delete mobile.price; would remove the price property, and console.log(mobile); would output 'Vivo V80'.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I built a lantern for memories that never leave your device

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine . What I Built Legacy Lantern is a private remembrance studio.

  • Legacy Lantern is a private, in-browser remembrance studio
  • Users input name, relationship, favorite things, and a cherished memory
  • Memory stays on user's browser, never leaves the device

Clojure Explained: A Modern Lisp on the JVM

Introduction Lisp is the second-oldest programming language still in use, and most programmers have never written it — yet its ideas (code as data, functions as values, macros) shaped everything after…

How to download all images from a website with Python (lazy-loaded, srcset and CSS backgrounds)

Right-click, "Save image as" does not scale past a handful of pictures. Here is a short Python script that downloads every image from a page, plus the traps that make naive scripts miss images or get…

  • Python script downloads all website images, including lazy-loaded and CSS backgrounds
  • Uses requests and beautifulsoup4 libraries for web scraping
  • Extracts image URLs from img tags, srcset, CSS backgrounds, and metadata

More from Tuesday 27 October →