Javascript Exception Handling Try-Catch-Throw - (Learning Javascript Series)

Javascript Exception/Error Handling

Exception handling is one of the difficult and oftenly avoided task by the developer. It is because handling exception requires almost equal amount of time and thinking from developer as given to the main program. In javascript 1.4 exception handling was supported by adding try-catch-throw to the language.

Exceptions are generally categorized in 2 types:

System Error: Caused by browser/code because of unknown reason(s).

Application Error: Caused by a piece of code where the scenario in which an error can occur is not handled by the developer.


Javascript Break, Continue and With Statements - (Learning Javascript Series)

Javascript Break, Continue and With Statement

Break and continue statements are part of almost every programming language. They provides ability to stop/skip the execution in a program flow. These statements are only used inside a loop or switch statement. They are not valid outside of switch/loop statement.

Break statement is most frequently  used inside switch statement and is part of every case block. Whenever a break is encountered after a case, execution is immediately sent out of switch. Similarily when it is used inside a loop, once break is found, execution comes out of loop. Break statement says, "Exit the loop."


Javascript Loop Statements - (Learning Javascript Series)


Javascript Looping Statements

Task iteration is one of the most frequently activity that every developer has to perform in most of its projects/applications. Iteration allows to repeat execution of set of statements for some definite time. It enables to avoid writing of same lines of code many times which not only is cumbor some but also waste of time.

Like other languages javascript also provide similar looping statements. Javascript looping statements are more like "C" language as most of the language syntax are derived from there.

So we can now summarise purpose of loop statements:

  • They provide ability to repeat a set of statements for a specific number of times
  • They provide ability to repeat a set of statemens for unknown number of times and/or can be stopped when some criteria is met during program execution


Javascript Conditional Statements - (Learning Javascript Series)

Javascript Conditional Statements

There are two conditional statements in JavaScript: if and switch. The if statement allows the program to choose one of two alternatives, based on some predefined factor.

If statement: It is used to interrupt program flow for some condition.

var num = 10;
                if (num < 20) {
                    alert(num + " is less than 20.");

If - Else: It is used to interupt program flow for some condition but instead of satisfying for one, it will also check for second condition.

var num = 10;
                if (num < 20) {
                    alert(num + " is less than 20.");
                else {
                    alert(num + " is greater than 20.");


Javascript Fundamentals - (Learning Javascript Series)

Javascript fundamentals

Let us learn the fundamental of javascript. This includes knowing the common programming terms related to javascript and also how to work with them.

Some of the most common terms are:

Statement: One line of programming code; statements are often separated by semicolons (;) in JavaScript.

Variable: A named location for storing values that can be changed during program execution.

Constant: A named location for storing values that cannot be changed during program execution.

Function: A named set of statements that perform some operation and can optionally return a single value.

Keyword: A word that has a predefined meaning in JavaScript, and cannot be used for any other purpose.

Operator: Typically a symbol (such as +, -, *, or / ) that takes one or more values (called operands) and returns a result.

Expression: A combination of keywords, operators, variables, and/or functions from which a result can be calculated.

String: A sequence of 0 or more letters, numbers, or other text characters; strings are typically enclosed in quotation marks, as in “Hello World!”.

Boolean: A value or expression that evaluates to either true or false.

Literal: A Boolean, number or string that is written directly in the code. For example the expression 22/7*radius*radius contains 2 number literals.

Value: A number, Boolean, string or object.


Javascript Alert, Prompt, Confirm and Write function - (Learning Javascript Series)

Javascript functions: alert, prompt, confirm and write

Alert, prompt and document.write functions are most commonly used for user interaction and writing some content on browser window.

  • Alert is used to display some warning message window
  • Prompt is used to capture user input
  • Confirm is used to capture Yes/No or OK/Cancel response from user in order to perform further activity
  • Write is used to write some text on browser window.

Below are some examples of using these functions.


Using Alert function:


var browserInfo = '';
        browserInfo = "Browser CodeName: " + navigator.appCodeName + "\n\r";
        browserInfo += "Browser Name: " + navigator.appName + "\n\r";
        browserInfo += "Browser Version: " + navigator.appVersion + "\n\r";
        browserInfo += "Cookies Enabled: " + navigator.cookieEnabled + "\n\r";
        browserInfo += "Platform: " + navigator.platform + "\n\r";
        browserInfo += "User Agent: " + navigator.userAgent + "\n\r";





Posts By Month