title: Which function is more efficient with respect to memory consumption?
body: <p>I am new to the world of JS and I want to know which of the 2 methods is more efficient and will consume less memory? Will variable <code>queryParams</code> and the returned value both consume memory in the first method?</p>
  
  <p>What are some of the good tools/ways to check memory consumption in JS?</p>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code>getQueryParamsForPreviousUrl(): string {
      let queryParams: string = '';
  
      if (this._currentUrl) {
        const index = this._currentUrl.indexOf('?');
  
        if (index !== -1) {
          queryParams = this._currentUrl.slice(index);
        }
      }
  
      return queryParams;
    }
  </code></pre>
  
  <p><strong>Method 2</strong></p>
  
  <pre><code>getQueryParamsForPreviousUrl(): string {
  
      if (this._currentUrl) {
        const index = this._currentUrl.indexOf('?');
  
        if (index !== -1) {
          return= this._currentUrl.slice(index);
        }
      }
  
      return '';
    }
  </code></pre>