Skip to content

Instantly share code, notes, and snippets.

View strothj's full-sized avatar

strothj strothj

View GitHub Profile
@strothj
strothj / package.json
Last active August 27, 2021 03:18
Yarn v3 patch: typescript@4.4.2
{
"resolutions": {
"typescript": "patch:typescript@4.4.2#./.yarn/patches/typescript.diff"
}
}
@strothj
strothj / package.json
Created July 7, 2021 12:22
Yarn 3 typescript@4.4.0-dev.20210704
{
"resolutions": {
"typescript": "patch:typescript@4.4.0-dev.20210704#./.yarn/patches/typescript.diff"
}
}
@strothj
strothj / .editorconfig
Created December 11, 2018 04:56
.editorconfig
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
@strothj
strothj / LICENSE
Last active March 30, 2024 11:35
ResizeObserver TypeScript definition
Copyright 2020 Jason Strothmann
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

What is scope? Your explanation should include the idea of global vs. local scope.

JavaScript has different scopes by which a variable can be accessed. In ECMAScript 5, there are two scopes. Globally scoped variables can be read and mutated from any script in the browser, not just the current function. Locally scoped variables can only be accessed from the function in which they were defined.

Why are global variables avoided?

Global variables should be avoided in most cases. Globally scoped variables make programs more difficult to test, more difficult for other developers to understand, and cause unintended side effects. When a functions uses a global variable instead of a parameter, it is more difficult to create reproducible results. A program with lots of global variables is more difficult for other programmers to reason about because it's not obvious what functions are using a given variable. This increases the difficulty in maintaining the software and adding new features. One function may modi

function computeArea(width, height) {
return width*height;
}
// tests
function testComputeArea() {
var width = 3;
var height = 4;
var expected = 12;
package khp
import (
"encoding/hex"
"errors"
"net"
"net/http"
"net/url"
"strings"
package sstream
import (
"bytes"
"io"
"sync"
"golang.org/x/net/context"
)