Six simple steps to install the pygment syntax highlighter in a Jekyll blog that uses bootstrap.

Highlighting your code-examples in your blog makes your articles simpler to read. When using Jekyll the “default” option for highlighting code is provided from the pygments plugin.

Read the complete article

Type-Casting aka Coercion in JavaScript. What you have to know.

With this article I plan to give in a quick and simple way the most important ways to convert JavaScript from one value type to another. Type casting is most often referred as coercion. There are two types of coercion. Explicit and implicit.

  • Explicit coercion is, most of the times, obvious to the programmer who reads a part of JavaScript code.
  • Implicit coercion is done more secretly and is not always obvious to the programmer, if she has not used an implicitly coercion operation before.
Read the complete article

Immutable Strings And Mutable Arrays

Strings in JavaScript are immutable which means that once a string is defined, it cannot be changed anymore. Trying to change a string with a standard String-function will only create a new string and not affect the original string. Consider the following example, where the value in string1 is not changed:

var string1 = "LOREM IPSUM";
Read the complete article

Data types in JavaScript

Inspired from an exercise in, I found the opportunity to present you the data types that JavaScript defines, which are the following six:

  • undefined
  • null
  • number
  • string
  • boolean
  • object

Arrays and functions are plain objects in JavaScript and they both belong to the object data type.

Read the complete article

Using a variable as a regular expression to find all matches inside a string

Often I have to use a value from a variable and not a fixed string inside a regular expression. For example if I wanted to iterate over the english alphabet and find the number of occurrences of each letter inside a string, I had to do something like the following:

var testString = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.";
var matches = testString.match(/a/g).length;
// do this for all the remaining letters

the previous example would work and would find all occurrences of “a”.

Read the complete article