Tuesday, November 4, 2014

JavaScript Methods for Pattern Matching

returned valueString methods
new_stringstring.replace(regexp, replacement_str)
returned valueRegExp methods

JavaScript Regular Expression

1. Defining Regular Expressions in JavaScript

In JavaScript, regular expressions are represented by RegExp objects. RegExp objects may be created with the RegExp() constructor or with a literal syntax. Regular expression literals are specified as characters within a pair of slash characters.
For example:
var regexp = /^Hello JavaScript$/;
This regular expression could have equivalently been defined with the RegExp() constructor like this:
var regexp = new RegExp('^Hello JavaScript$');

Advanced Regular Expression Features

If you want to employ all regular expressions constructs and features you can't make it with a simple shell command or a tool, but you need to use a programming language. I use Perl, because it has the best and longest established support for regular expression.

Parenthesized Subexpressions

Earlier, we saw that regex engines support metacharacters \1, \2, \3, etc. to refer to the text matched by parenthesized subexpressions. Perl and most other modern regex-endowed languages also provide a way to refer to the text matched by parenthesized subexpressions from code outside of the regular expression, after a match has been successfully completed.

Saturday, November 1, 2014

Introduction to Perl

This guide introduces the Perl language through a number of sample programs. The aim of this guide is to understand how to use regular expressions with Perl.

1 - What is Perl Language

Perl is a scripting language suitable for web-processing. Perl was developed deriving its concepts of text handling and regular expression from two specialized languages called awk and sed.

Tuesday, July 29, 2014

Regular expressions Introduction

1. What is a regular expression?

"A regular expression is a pattern which specifies a set of strings of characters; it is said to match certain strings."[Ken Thompson]

From the English dictionary:
  ●   pattern = (noun) a regularly repeated arrangement of something.
  ●   to match = (verb) to be equal.

A regex can or cannot match a string and, if it does, can match the string once or multiple times.

Monday, March 17, 2014

The <script> element

The unobtrusive javaScript programming paradigm

Unobtrusive JavaScript is an approach to web programming that supports separation of behaviour (JavaScript code), structure (HTML code) and presentation (CSS code).
According to this programming paradigm, to accomplish separation is best to write all your JavaScript in an external file and embed it in HTML document using a <script> element with src attribute.

The <script> element is synchronous by default

Let's examin how the <script> element allow you to insert javascript in a HTML document.
<script src="scripts/javascript_app.js"> </script> <!--synchronous script-->

When JavaScript engines encounters a <script> element, they stop parsing HTML to download and interpreter the JS file, then they resume parsing and rendering HTML.

The <script> element has two important attribute: HTML 4.1 defines the async attribute and HTML5 introduces the defer attribute. These two attributes cause scripts to be executed differently, in browsers supporting them.

JavaScript Versions

JavaScript Birth

JavaScript was created at Netscape in 1998, and the name JavaScript is a trademark of Oracle. Netscape submitted the language for standardization to ECMA (the European Computer Manufacturer’s Association) and, because of trademark issues, the standardized version of the language was given the name ECMAScript.

Browser Vendors' Names for JavaScript

Mozilla calls its ECMAScript implementation JavaScript and Microsoft JScript.

JavaScript Versions

By 2008, all major web browsers were compliant with the standard ECMAScript version 3.
In December 2009, ECMAScript version 5 was defined and the first browsers to implement it were Internet Explorer 9 and Firefox 4.
The only versions that are relevant are ECMAScript version 3 and 5.


Saturday, March 8, 2014

JavaScript Type Conversions

1. Implicit Types Conversions

JavaScript is flexible about the types of values it needs. When JavaScript expects a boolean value, you may supply a value of any type, and JavaScript will convert it automatically as it needs. If JavaScript wants a string, it will convert whatever value you give it to a string. If JavaScript wants a number, it will try to convert the value you give it to a number.

Truthy values and falsy values

The following six values convert to false and are also called falsy values:
undefined, null, 0, -0, NaN, ""
All other values (comprised any object and any array) convert to true and work like true.

Friday, February 28, 2014

JavaScript Data Types

JavaScript Data Types
Primitive Types
Object Types
  • string
  • number
  • boolean
  • null
  • undefined
fundamental Object types
specialized Object types
  • Object
  • Array
  • Function
  • Date
  • RegExp
  • Error

Sunday, February 16, 2014

JavaScript Execution Contexts

1 - Execution Context or Context

The execution context or context is the environment where JavaScript code is evaluated.
→ Global (execution) context
The global execution context is the most outer execution context.
In browsers the global context is also known as window context. In a browser global variables are window properties and global functions are window methods. 
→ Function or Local (execution) context
When a function is called a function execution context is created.

Friday, January 31, 2014

Java VS JavaScript

Java VS JavaScript

Java JavaScript
language features semi-compiled semi-interpreted
object oriented
functional only from Java 8
strongly typed
classical inheritance
object oriented
lambda or functional
loosely typed
prototypal inheritance
data types classes and primitives objects and primitives
namespace package namespace object/function namespace
meaning of object objects or class instances objects or reference types
meaning of class classes as blueprint for objects constructor functions for building classes of objects
meaning of this keyword a reference to the current object a reference to the current context
how to implement utility functions static methods for utility functions objects in the global scope for utility functions