Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 1684

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T10:26:07+00:00 2024-11-25T10:26:07+00:00

Day 64 / 100 Days of Code: Destructured Assignment

  • 62k

Mon, Sep 2, 2024

If JavaScript Syntax initially seemed a natural extension coming from C/C++, the advanced object features I’m now seeing are a masterful revival.

One characteristic of computer languages that is foundational is that, with rare exceptions, they are always backward compatible. This is crucial so that legacy code can continue to operate 10, 15, or 20 years after it was written. Code that’s been tested and proven reliable is what we want running our Air Traffic Safety Control system. However, while backstopping is crucial, that doesn’t mean language development must flatten.

JavaScript is an implementation of the ECMAScript standard, and every year or two, there are new releases. The most significant was ES6 in 2016, which all major browsers have supported since 2017. JavaScript used to only operate in web browsers, but in 2009 Node.js was released, bringing JavaScript to application developers everywhere.

I've mentioned how arrow functions and for..in and for..of loops abstracted data from traditional programming design patterns. Well, JavaScript was just getting warmed up, because it has some pretty powerful tools under its belt. Recalling that an object is a collection of tailored properties and functions, JavaScript deploys the following:

// Example: The Millennium Falcon, see Footnote  const millenniumFalcon = {   modelNumber: "YT-1300F",   yearOfProduction: "56 BBY", // Before the Battle of Yavin   engineCapacity: "2 Girodyne SRB42 sublight engines",   rateOfTravel: {     atmosphericSpeed: "1,200 km/h",     spaceSpeed: "3,000 G",     hyperdrive: "0.5 HCR (Hyperdrive Class Rating)"   },   currentSpeed: "800 km/h", // Example current speed   logCurrentSpeed() {     console.log(`Current Millennium Falcon speed: ${this.currentSpeed}.`);   } };  millenniumFalcon.logCurrentSpeed(); // Output: Current Millennium Falcon speed: 800 km/h. 
Enter fullscreen mode Exit fullscreen mode

The this keyword is a means for securely accessing only one object’s data, namely the one being accessed. If the logCurrentSpeed method attempted to access the currentSpeed without using this, the result would be undefined. Using this provides the correct context.

As the Rebel Alliance needs a fleet of starships to defeat the Galactic Empire, JavaScript comes to the rescue with Factory Functions to produce objects, here Starships, en masse! Note: Property Value Shorthand is used to reduce retyping parameters.

// Factory function for creating Starships function createStarship(type, model, name, speed) {   return {     type,     model,     name,     speed,   }; } 
Enter fullscreen mode Exit fullscreen mode

Finally, JavaScript provides Destructured Assignment to simplify assigning an object’s property to a variable. Compare:

const engineCapacity = millenniumFalcon.engineCapacity; const { engineCapacity } = millenniumFalcon;  We can even use destructured assignment to grab nested properties: const { hyperdrive } = millenniumFalcon.rateOfTravel; 
Enter fullscreen mode Exit fullscreen mode

JavaScript’s advanced object features provide powerful tools for developers, making it easier to write clean, efficient, and maintainable code. As you continue your coding journey, keep exploring these features and see how they can enhance your projects.


Footnotes
The Millennium Falcon is an extensively modified Corellian YT-1300 light freighter. Known for its speed and agility, the Millennium Falcon was primarily used for smuggling and later became a key asset for the Rebel Alliance

100daysofcodebeginnersjavascriptwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers
  • Author

    Refactoring for Efficiency: Tackling Performance Issues in Data-Heavy Pages

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.