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

  • Home
  • SEARCH
  • 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 8515539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:10:30+00:00 2026-06-11T05:10:30+00:00

I am wondering Can you assign a variable to alert ? what does it

  • 0

I am wondering Can you assign a variable to alert ? what does it really mean and do ? For example,

var a = alert('test');  

I tried it out, and the alert pops up as soon as the page loads where variable a remains 'undefined' when I call it. Aren’t we suppose to make it an anonymous function with the alert inside like

var a = function(){ alert('test'); }

If we want to trigger an alert on something? Why does javascript allow you to do that?

  • 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-06-11T05:10:31+00:00Added an answer on June 11, 2026 at 5:10 am
    var a = alert('test');
    

    Think of this statement like any other variable assignment. In order to perform the assignment, first the right-hand side is evaluated. In this case it’s a function call, so the function is called and its return value is obtained. In alert’s case, the return value is undefined. It doesn’t return anything.

    Then the return value is assigned to a, so a ends up with the value undefined.

    As a side effect of the statement, an alert message is displayed. That happens as a consequence of calling alert() and getting its return value.

    function foo(x) {
        return x * 2;
    }
    
    var a = foo(3);
    

    This code is structurally similar to the alert call, and would result in a being 6. But then alert() doesn’t return a value. It’s more like this:

    function bar(x) {
        return;
    }
    
    var a = bar(3);
    

    Now a is undefined.

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

Sidebar

Related Questions

I was wondering if i could assign values to a variable inside an IF
I am wondering if you can assign a status to .page or dcr files
I can't do this but wondering what would work: is_object(new Memcache){ //assign memcache object
Wondering why I can't get document.getElementById("my_div").innerHTML to update the DOM when I re-assign the
I know you can assign a function's return value to a variable and use
i was wondering how i can get users to sign up and assign them
This might be very basic question but I was wondering why can't I assign
was wondering how can I create a sub drop down box upon selecting a
I was wondering how can I track the current logged in user in a
I was wondering how can I control the image on the connect dialog? I

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.