Skip to main content

Posts

Showing posts with the label JavaScript

Execption Handling in js

Hi every one,👋 Today I’m going to discuss about exceptions occur in java script. This is one of advance topic in java script and really important to have an idea about exception handling in js. First we move on to errors in java script. There are 3 types of errors in programming. Figure 1 Syntax errors occur when we miss any kind of syntax inside the codes. Like, Figure 2 Run time errors occur during execution. It bot because of any syntax errors. It happens like, trying to call a method but that method is not exist. Ex: <script type = “text/javascript”> document.getData(); </scrip> Logical errors are occur due to logical mistakes that happen by programmers. Because of these errors we can’t get the actual result that we need. When there is any run time error (exception) happen in the java script code we can handle them before the execution of the program. There are 3 types of handling ways ·      ...

void in java script

Hi, 👋 this is my 13 th JavaScript tutorial which is describe about void keyword in js. My previous tutorial is about math object in js. You can go through it too.👍 So I thought to explain about less heavy concept in here. Because last tutorials were so long. (But this is also an important concept) Ok let’s go to the point.👇 So we are going to learn about void keyword in js. What is void???💭 It is an important keyword which is not evaluate a return value.  That mean when we use void as java script function signature, then the function does not return any value. So it takes an expression of any type as its operand and returns undefined. OK. Let’s go to an example on js void. <html> <head> <title> java script void </title> </head> <body> <form name= my_form> <a href=”javascript:void (alert(‘Hi this is first void example !!!’))”>Clck here</a> </form> </body> </html> ...

math object in java script

Hi, ✋ this is another new tutorial which is explain Math object in java script. Using math object we can access lots of mathematical constants and functions. So, let’s start math object.👇 Think you need to use the cos function. So you just have to type Math.cos(x). It’s simple! Here I have listed some Math properties.       À      Math.PI                 = this returns the value of π. (3.14)       À      Math.E                  = this returns the Euler’s constant. (2.718)       À      Math.LN2             = this returns the natural logarithm of 2. (0.693)       À      Math.LOG2E        = this...

java script Arrays

Hi everyone.👋 This is my 10 th js tutorial which is explain about Arrays in java script. If we consider an array as an object we can store multiple values of data in same type. This is the syntax for array var myArray = [“dog”,”cat”,”lion”,”monkey”,”tiger”]; or var myArray = new Array (“dog”,”cat”,”lion”,”monkey”,”tiger”); So according to this array elements can identify as myArray[0] = dog🐶 myArray[1] = cat🐱 myArray[2] = lion🦁 myArray[3] = monkey🐵 myArray[4] = tiger🐯 There are some properties of arrays that we can use them for various conditions. length property      = can get the array size index property       = can get the element that indexes from zero prototype property = this property allows to add properties and methods to any object Figure 1 This is the result: Figure 2 This prototype property is very important property in arrays. We can use it in various places which is used to add new p...

java script Objects (part two)

Hi this is my 9 th js tutorial and I hope to continue previous lesson which describe about objects. So we discussed how to create an object, how to initialize values to objects and object constructors. In this tutorial I hope to cover all the theories of js objects. So let’s move on!!! We can use methods to perform a task in js. (You know that in js functions tutorials) But without calling the function it is useless. So we can create object and call the function to perform the task or for given output. It is like this. Figure 1 Figure 2 We have lots of things to learn in js objects. This objects is the almost everything in js. As a beginning I hope this is enough for now and I hope to do more things using some examples future. Thank you✋!

switch-case in js

OK here I will show the switch case usage of js.  This is my 6 th Java Script tutorial and I have followed more basics on last 5 tutorials. You can check them in blog. https://chamzzdot.blogspot.com/ Ok let’s move on. Switch statement This works like if else statement. But it is more efficient and no need to code much like if else. Think you have 5 marks for your mathematics paper. This is the grade list in your college that depend on your marks. Assume that the maximum score is 6.😉 6 =A 5 =B 4 =C 3 =D 2 = E 1 = F So you need to write js program to find your grade. For now you have to remember what you can use for that. Yes, it is if else. See this, Figure 1 But we can get the same result with more efficient code by using switch case. OK I will explain switch case using flow chart first. Figure 2 Ok I will explain what the flow chart says. First we have to go inside to the switch case by having a situation (case). But inside the progra...

For loop

 Figure 1 Hope now you have a little idea about this flow chart. Here if the statement is true it go inside the loop and if the statement is false it will be end. To use this for loop you have to use an initialized counter. for(count = 0; count < 10; count++){ //statements to execute when the counter is less than 10 }   OK This is an simple example which use for loop to print even numbers from 0 to 10. Here you need not only for loop knowledge. You need also if else statement to check whether the number is even or not.                                                                        Figure 2 Look the output is here…                                          ...

Variables

Hi people, this is my third js tutorial which explains about using variables with js. So, let’s move on. Before use variables we must declare variables. For that we have to use  var  keyword. Ex:         var first_name,last_name;      var age=23;       var country= “Srilanka”;       When we create functions in js we use local variables inside function. The specialty of local variable is the value of the local variable will destroy once it exits the function. So, the other thing is you can use global variable in anywhere within the js code. See the below code. Figure 1 Did you see? Here first I defined variable   var_   as a global variable. Then within the  variableChecking() , I declared   var_   again as a local variable. So, within the function it is a local var. But in outside the function it is a global variable. You...