Same origin policy in JavaScript
The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin.
Two pages have the same origin if the protocol, port (if one is specified), and host are the same for both pages.
When using document.domain to allow a subdomain to access its parent securely, you need to set document.domain to the same value in both the parent domain and the subdomain. This is necessary even if doing so is simply setting the parent domain back to its original value. Failure to do this may result in permission errors.
- References
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
http://lucybain.com/blog/2014/same-origin-policy/
Difference between JS Varaible that is null, undefined, undeclared
- undeclared variables don’t even exist
- undefined variables exist, but don’t have anything assigned to them
-
null variables exist and have null assigned to them
- References
http://lucybain.com/blog/2014/null-undefined-undeclared/
Truth and Falsy in JavaScript
Javascript auto converts any value used in Boolean context (example an if
condition)
to either true
or false
. This way of implicitly converting a type is
called as Implicit Type Coercion.
In JavaScript, a truthy value is a value that is considered true
when
evaluated in a Boolean context.
A falsy value is a value that translates to false
when evaluated in a
Boolean context.
The following values are treated as false
.
false
0
(the number zero)""
or''
(an empty string)null
undefined
NaN
(the result of failed mathematical operations)
All values are truthy unless they are defined as falsy
(i.e., except for false
, 0
, ""
, null
, undefined
, and NaN
).
The falsy values null
and undefined
are not equivalent to anything
except themselves.
The falsy value NaN
is not equivalent to anything — including NaN
!
Use strict equal (===
) and strict not equal (!==
) in situations
where truthy or falsy values could lead to logic errors.
We can test for several types of invalid data by simply passing a variable into an if expression.
if (value) {
// value is truthy
}
else {
// value is falsy
// it could be false, 0, '', null, undefined or NaN
}
References
How to write Git commit message
Below are The seven rules of a great Git commit message.
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
-
Use the body to explain what and why vs. how
- References
https://chris.beams.io/posts/git-commit/
https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project
How to search bash command history in Emacs multi term
C-r in Emacs multi term invokes (isearch-backward) command. To search bash command history we can use M-r instead.
- Reference https://www.emacswiki.org/emacs/MultiTerm