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 1074915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:12:05+00:00 2026-05-16T21:12:05+00:00

if i don’t specifically type a variable in my code will it compile as

  • 0

if i don’t specifically type a variable in my code will it compile as a default datatype? for example, the “for each … in” function works best without typing the variable:

for each (var element in myArray)
         {
         //process each element
         }

does my element variable have a datatype? if it is typed as Object is it better to actually write element:Object or does it matter?

EDIT

actually, that was a bad example, since the element variable is going to be typed to whatever element is in myArray.

but is that how it works if a variable is untyped? it will simply become what is passed to it?

here’s a better example for my question:

var a = "i'm a string"; //does this var becomes a String?

var b = 50.98; //does this var becomes a Number?

var c = 2; //does this var becomes an int?
  • 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-16T21:12:06+00:00Added an answer on May 16, 2026 at 9:12 pm

    for each (var element in myArray)

    The element variable doesn’t have any data type – it is untyped and thus can hold anything.

    And yeah, it is equivalent to writing element:Object or element:*, but it is always advisable to type your variables – this will help you catch some errors before you run the code. The mxmlc compiler will emit a warning if you don’t do this, which can be fixed by typing it as e:Object or e:*.


    var a = 45.3;  //untyped variable `a`
    a = "asd";     //can hold anything
    
    /*
        This is fine:  currently variable `a` contains 
        a String object, which does have a `charAt` function.
    */
    trace(a.charAt(1));
    
    a = 23;
    /*
        Run time error: currently variable `a` contains 
        a Number, which doesn't have a `charAt` function.
        If you had specified the type of variable `a` when 
        you declared it, this would have been 
        detected at the time of compilation itself.
    */
    trace(a.charAt(1)); //run time error
    
    
    var b:Number = 45.3; 
    b = "asd"; //compiler error
    trace(a.charAt(1)); //compiler error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know how to frase this but I found this code wich works as
Don't be scared of the extensive code. The problem is general. I just provided
I don't know why, but this code worked for me a month ago... maybe
Don't think that I'm mad, I understand how php works! That being said. I
Don't be frightened, its a very basic code. Just wanted to check with you
Don't they both have to convert to machine code at some point to execute
I don't know: if this works. if it's a good idea. what it is
Don't know if this is the right place to ask this, but I will
I don't have much PHP experience and I want to know how to best
Don't think there's much to say, here's my code for (int i = 0;

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.