What does it mean when curly brackets just wrap the code?

Viewed 175

When I checked the source code of Vue.js, I saw that there are lines of code between two curly brackets and there is no any definition before this construction (like function, ()=> or another thing). I paste it in the console and it runs. But how can I use it, if I dont assign it to a variable?

What is this? Why should we use this way when we write code?

....
 var formatComponentName = (null); 

    {
      var hasConsole = typeof console !== 'undefined';
      var classifyRE = /(?:^|[-_])(\w)/g;
      var classify = function (str) { return str
        .replace(classifyRE, function (c) { return c.toUpperCase(); })
        .replace(/[-_]/g, ''); };

      warn = function (msg, vm) {
        var trace = vm ? generateComponentTrace(vm) : '';

        if (config.warnHandler) {
          config.warnHandler.call(null, msg, vm, trace);
        } else if (hasConsole && (!config.silent)) {
          console.error(("[Vue warn]: " + msg + trace));
        }
      };

      tip = function (msg, vm) {
        if (hasConsole && (!config.silent)) {
          console.warn("[Vue tip]: " + msg + (
            vm ? generateComponentTrace(vm) : ''
          ));
        }
      };
    }
    ...
1 Answers
Related