Thursday, May 30, 2013

javascript lesson 1

I am learning javascript tutorial from that website i mention www.codeacademy.com
since it is very interactive not much to post here

//   - for writing comments

to open popup  boxes we use these functions
confirm();
or prompt();

we use prompt() cmd for example
prompt("what is your name?");

this function will take your name as input

the confirm() function will take input as 'true' or 'false'

.length counts every character in the string including spaces
ex: "i am good".length  gives o/p as 9

we can directly get evaluating expressions, for example 5<4 yields 'false'

strings are always in between the " "

console.log() shows what the interpreter is doing completely
ex: console.log(4*5)
console.log("hello")
the o/p shows all the steps including intermediate steps, not just the final result.
These console.log() can used to check how much or which direction did the javascript program traverse and line number as well

and the if loops are very very similar to 'C' language more than the shell scripts i learnt yesterday.
the syntax is
if (2 > 4)
{

}

as we all know that % is used to calculate remainder
4%5 gives 4

there is a substring function as well
ex: "wonderful day".substring(3,7);
this will output from 4th letter to 7th letter
remember the numbering in string starts from 0

To define variable in javascript, we do this

var variable1 = "string";
var number2 = 2;

another one of the most confusing things in the programming of any language is postfix and prefix increment/decrements

var++ : the o/p is evaluated but the old value is returned
--var   : the o/p is evaluated but the new value is returned

this is my first experience of the first part of tutorial , it is fun and very interactive  to learn using this website. I recommend it to anyone who wants to learn programming. This website pleases even the fastidious people as well.

No comments:

Post a Comment