Accessing customizer values in javascript

Given a setting with an ID of “foo” you can obtain the value via:

var value = wp.customize( 'foo' ).get()

To ensure that the setting is registered before you attempt to get its value, you can use this deferred pattern:

wp.customize( 'foo', function( setting ) {
    var value = setting.get();
    // ...
});

This should look familiar because these calls are very common in JS that gets enqueued in the Customizer preview for handling setting change previews via postMessage.