All posts in javascript

Dynamically add deep links to a page

As you can see, I have republished my blog with a new design. It's built with Sandra.Snow (a static site generator written in Nancy) from the awesome Phillip Haydon. All posts are written in markdown and get automatically compiled to HTML by the generator. A requirement for a good blog post for me is to be able to deep …
read story

Query meta tags with vanilla JS

The following code demonstrates on how to easily fetch a meta attribute from your HTML. This supports all HTML-compliant meta properties as well as Open Graph properties, whose key starts with og:. If you want to fetch all vendor meta properties (e.g. "twitter:creator"), you can simple replace the following line if( key.split(':')[0] === 'og' ) with …
read story

Multi-line JavaScript strings

Just to list the popular ones: The Unreadable var catastic = 'my\ncat\nis\ncatastic!'; Array join [ 'my', 'cat', 'is', 'catastic!' ].join('\n'); String concatenation 'my\n' + 'cat\n' + 'is\n' + 'catastic!' This is pretty neat. Array joins give you the possibility to easily modify the new-line char, but it feels a bit like abusing Arrays just …
read story

Unary + (plus) operator in JS

The plus-sign is used for numeric addition or string concatenation. It internally calls valueOf() or toString() on its operands and can also be used as an unary operator, which takes 1 operand. If a operands type gets converted within the + operation - like "2" (string) to 2 (number) - it's called a implicit coercion. David Herman wrote a brilliant chapter …
read story