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

You must login to ask a question.

Forgot Password?

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:14:23+00:00 2026-05-29T08:14:23+00:00

I have a section of Javascript/Coffeescript that seems to be executing out of order.

  • 0

I have a section of Javascript/Coffeescript that seems to be executing out of order.

console.log list
console.log list[card_number]
if list[card_number]
  console.log "MATCHES"
  new_card = list[card_number]
else
  console.log "NO MATCHES"
  new_card = create_new_card(card_number)

create_new_card: (card_number) ->
  new_card =
    card_number: card_number
  list[new_card.card_number] = new_card
  return new_card

Every time I run this, the first console.log shows a list of cards that includes the new_card, Even if the card hasn’t been created yet. Then it ALWAYS hits the else, no matter how many times it is run.

If I attempt to run list[<card_number>] in the Javascript console after this code runs, I receive the proper object, but each time the code runs on it’s own, the same event happens.

  • 1 1 Answer
  • 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

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:14:24+00:00Added an answer on May 29, 2026 at 8:14 am

    In google chrome, if you want to log objects with the state they had at the time of logging, you need to log a clone object or just stringify it.

    var a = [];
    console.log(a);
    a[0] = 3;
    

    Will log [3] because it logs a live object, while this will log []:

    var a = [];
    console.log(JSON.parse(JSON.stringify(a)));
    a[0] = 3;
    

    It is also a live object logging but it is a throwaway clone that was cloned at the point in time when a didn’t have any items.

    This is not related to the possible logical errors in your code that @CallumRogers pointed out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of a webpage that loads a JavaScript file from an
Given that I have a JavaScript section in my HTML page like : <script
I have a section of simple Javascript in my application that has a link
Javascript I have code that will hide various sections in a MS CRM form
I have a section of makefile that has this sort of structure: bob: ifdef
I have a section of code that is being used to determine if a
I have a section of code that can be summarised as follows; void MyFunc()
i have a section in my website that needs to be toggled by clicking
I have these lines in my html head section <script type=text/javascript src=../behaviour/location.js></script> <script type=text/javascript
I have some simple JavaScript that determines where a click happens within a browser

Explore

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

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.