In this article, I am going to cover all basics stuffs like commenting,variables,functions,arrays,loops and soon in javascript.
Through this article, focusing on regular code snippets ,examples and syntaxes which often searched in google by all developers.
My motto is "keep all work related code in one place then save a lot of time to developer/user."
The below examples are written in JS file.
1. Show string,Numbers,... without using console,documet.write,...in Javascript
Ex 1: "MyStuff"
Output : Mystuff
Ex 2: 2+3
Output : 5
2. Find length of given string?
Ex : "MyStuff".length
Output : 7
3. If user tried with custom name as event in Javascript
Ex : mystuff("alert me");
OutPut : ReferenceError: mystuff is not defined
4. In javascript, comments is represented in below way
Ex : // This block will tell about calculate the tax
function calucate(amt,taxamout)
{
//------
}
5. Confirmation box before deleting any record then use confirm()
Ex : confirm("Are you sure want to left from site?");
6. If application want to know user opinion then should use prompt()
Ex : prompt("Are you accepting this law?"); - then it asks the user to enter their opinion
7. Order of operations
Operators:
1. ( ): control order of operations
2. * and /: multiplication and division
3. - and +: subtraction and addition
Examples:
1. 100/10 evaluates to 10
2. "mystuff".length + 2 evaluates to 8
3. 5*(3+1) evaluates to
8. Substrings - Display part of string from original string.
Syntax : string.substring(x,y);
where x- start and y-end
In substring, character position starts from 0 .
9. Functions - avoid writing repetitive code
Ex: Function Definition
var divideByThree = function (number) {
var val = number / 3;
console.log(val);
};
Calling Function
divideByThree(6);
10. Variables vs Arrays
Variables - Store any type of data,Store only one data of any type.
Syntax of variable : var variablname="Nuthan";
Arrays - Store any type of data, store any no.of data of any type at a time in one array.
Syntax of array
var arrayname=["Nuthan","sree"];
var arrayname=["29","9"];
Ex : var junk=["nuthan","Sree",29,9];
console.log(junk);.
- In array, position of data is start with '0'.
" not yet completed and i come up with new concepts in javascript soon."
Happy Coding :)