Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
Call or access nested const inside variable in Javascript

i'm newbie in javascript but i need help, can i access or call from outside a variable inside const block ? , from code in bottom, i need to access layerAttributes which the variable is inside addAttributes block, i try to console.log(layerAttributes); inside block is working, but i don't know how to call it from outside block, biggest appreciate for help and thank's in advance.

const addAttributes = (_element) => {
  let selectedElement = _element.layer;
  const layerAttributes = {
    trait_type: _element.layer.trait,
    value: selectedElement.traitValue,
    ...(_element.layer.display_type !== undefined && {
      display_type: _element.layer.display_type,
    }),
  };
  console.log(layerAttributes);
  if (
    attributesList.some(
      (attr) => attr.trait_type === layerAttributes.trait_type
    )   
  )
    return;
  attributesList.push(layerAttributes);
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As far as I understood you want to be able to access layerAttributes from outside the block, you can declare it outside then use it inside the const block and outside like this:

let layerAttributes = {}; //declared outside the block
    
    const addAttributes = (_element) => {
      let selectedElement = _element.layer;
      layerAttributes = { //accessed inside the block
        trait_type: _element.layer.trait,
        value: selectedElement.traitValue,
        ...(_element.layer.display_type !== undefined && {
          display_type: _element.layer.display_type,
        }),
      };
      console.log(layerAttributes);
      if (
        attributesList.some(
          (attr) => attr.trait_type === layerAttributes.trait_type
        )   
      )
        return;
      attributesList.push(layerAttributes);
    
    }; //end of block

    console.log(layerAttributes); //accessed outside the block

tell me if this is what you meant

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!