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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:45:14+00:00 2026-06-13T13:45:14+00:00

In a jQuery.each() loop, I always thought that this was equivalent to valueOfElement .

  • 0

In a jQuery.each() loop, I always thought that this was equivalent to valueOfElement. Could someone explain the difference?

Example:

$.each(object, function(i, val){
    $('body').append('<b>valueOfElement:</b> ' + typeof val + ' - ' +  
    '<b>this: </b>' + typeof this + '<br/>');
});

Result:

valueOfElement: string - this: object
valueOfElement: boolean - this: object
valueOfElement: object - this: object

Fiddle

  • 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-13T13:45:15+00:00Added an answer on June 13, 2026 at 1:45 pm

    The answer is in the documentation you linked to :

    The value can also be accessed through the this keyword, but
    Javascript will always wrap the this value as an Object even if it is
    a simple string or number value.

    All values are embedded in objects when accessed as this.

    The real reason can be found in this line of jQuery source :

    callback.call( obj[ i ], i, obj[ i++ ] ) === false ) {
    

    You can compare it to

    (function(){console.log(this)}).call(1);
    

    which builds a Number, because you can’t call a function on something that isn’t an object.

    From MDN on the call function :

    thisArg :

    Note that this may not be the actual value seen by the method: if the
    method is a function in non-strict mode code, null and undefined will
    be replaced with the global object, and primitive values will be
    boxed.

    The only advantages I would see in using this instead of valueOfElement are :

    • simplicity : you don’t have to keep in mind the order of arguments given to the callback
    • ability to use a function directly on this even if valueOfElement is of primitive type
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside the initialize() function there is a jQuery each loop. Inside that loop is
Is there a way (in jQuery or JavaScript) to loop through each object and
For example: > function foo() { > jQuery(whatever).each( function() { return; // this just
This js loop script always get the last value of ui_item inside a jquery
I'm trying to use jQuery's each loop to go through this JSON and add
So, I have this jQuery .each loop, and for the most part its working
I want to parse this json using jquery and each with a loop. I
I have a jQuery each loop that runs through a list of three JSONP
I have a JQuery's .each loop that calls a function with a parameter per
I have an .each loop in jQuery. I want to iterate the loop one

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.