One strategy that can be effective in avoiding global variables is using a self-executing closure:
// bob is a global variable, but you want to avoid that
var bob = 1;
// By enclosing this function declaration in parentheses and immediately invoking it,
// everything inside is scoped to the anonymous function!
(function () {
// sue is only accessible within this function
var sue = 1;
// If necessary, you can still create global variables.
// This line creates a global variable named joe:
window.joe = 1;
})();
Implementing this approach in your code allows you to eliminate any reliance on global variables:
(function() {
var size_li = $("#myList li").size();
var x = 3;
$('#myList li:lt(' + x + ')').show();
$('.loadmore').on('click', function() {
x = (x + 2 <= size_li) ? x + 2 : size_li;
$('#myList li:lt(' + x + ')').show();
});
})();