Sharepoint - Get a list Id using javascript?

Should be some thing like following

var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Name of the List');
context.load(list, 'Id');

In the success, try

var listId = list.get_id();

Update for web is undefined

Run code under ExecuteOrDelayUntilScriptLoaded()

ExecuteOrDelayUntilScriptLoaded(getListId, "sp.js");
var list;

function getListId() {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    list = web.get_lists().getByTitle('Name of the List');
    context.load(list, 'Id');

    context.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, error));

}


function success() {
    listId = list.get_id();
    console.log(listId);
}

function error(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}