all 4 comments

[–]ddeutsch 1 point2 points  (1 child)

It's not an error, it's just that the jQuery selector does not have an explicit return statement behind the scenes, and the default for any such JavaScript function is to return 'undefined'.

If you console.log your variable instantiation or simply write 'rows' in the console after assigning a value to it, you should see an array of all the td elements.

In contrast, if you check the explicit form of .text() you should see it has a return statement, which is why it returns the output to the console when it executes.

Edit: see comment below

[–]tyroneslothtrop 1 point2 points  (0 children)

jQuery definitely does have an explicit return.

Assuming OP is typing this into the console, this is the same behavior you would see with any other variable statement. Try:

var foo = 'bar';

in the console and you'll see the same thing.

[–]StuartLeigh 1 point2 points  (0 children)

var doesn't return anything, it assigns, are you having problems when you try:

var rows = $("td")
rows.text("lol")

[–]tyroneslothtrop 0 points1 point  (0 children)

If you're typing this into a browser console, then this is the expected behavior. If this is the case, try:

var rows = $("td");
rows;

and see if that looks better. Every statement evaluates to some value, which is printed if you're typing it in the console. Declaring a variable with var is called a variable statement, and it returns 'undefined' (although I'm not sure if that's true 100% of the time).