Reputation: 1733
(function(){
var commentList = $("#commentList");
});
Given the context above will commentList
get evaluated every time use the variable?
Upvotes: 0
Views: 1944
Reputation: 16713
It is evaluated once, when the assignment takes place.
Demo: http://jsfiddle.net/PxRXF/
Upvotes: 2
Reputation: 2339
No. You can easily check it
<script>
$(function(){
var commentList = $("#commentList");
console.log(commentList);
$('#commentList').html('');
console.log(commentList);
});
</script>
<div id="commentList">Test</div>
Upvotes: 2
Reputation: 34556
It will be evaluated afresh each time the function is called.
Once inside the function, it will be evaluated once, not each time the var is called.
Upvotes: 2
Reputation: 123397
no, that variable will store a reference to it, so every time you use commentList
you won't also re-evaluate $("#commentList")
(except for the first assignment, of course)
Upvotes: 2