Jump to content
jumaji3

Omar's Programming with JavaScript --Basics

Recommended Posts

I thought i would share some of my knowledge on Javascript with all of you guys.

Note: i created this back in 2011-2012. This is the first time i'm sharing it with anyone.

[COLOR=#ff0000][SIZE=4]PROGRAMMING WITH JAVA SCRIPT
[/SIZE][/COLOR]
INSTEAD OF OTHER GUIDES WHERE ALL YOU ARE GIVEN IS CODES, I ACTUALLY EXPLAIN WHAT THE HELL YOU ARE CODING. PLEASE TAKE THE TIME TO READ EVERYTHING. THAT'S THE ONLY WAY YOU WILL TRULY UNDERSTAND JAVA SCRIPT.





[COLOR=#0000ff][SIZE=3]CHAPTER 1
[/SIZE][/COLOR]
Server Side

• Server side scripts reside on the server (main computer) while client side scripts reside on a user PC
• Storing all programs on the server allows multiple users simultaneous access but poses potential connection and performance issues.


Client Side
• While client side scripts are not as powerful and will never fully replace server side scripts, they do offer a convenient alternative for performing some of the simple, low-key tasks locally.



Why JavaScript?
• HTML allows developers to create static web pages, the information and look of the page does not change.

• JavaScript allows you to create pages where content and layout can be modified using special code built into the page.


[COLOR=#ff0000][SIZE=3]Java vs. JavaScript
[/SIZE][/COLOR]

[COLOR="#800080"]I included this for people who have no knowledge of Java or Javascript and would like to know the difference.[/COLOR]

Java
• Code is powerful but complex
• A special app (JDK) required
• Programs must be saved and compiles separately
• Used for complex tasks


JavaScript
• Code is easy to learn and to use
• No additional software is needed
• Code can be added directly anywhere in the HTML text editor
• Used for quick, simple tasks

[COLOR=#ff0000][SIZE=3]Code Example[/SIZE][/COLOR]


[CODE]
<script>
document.write(“Today is 12/20/2011 <BR>”)
document.write(“Only 10 days until the New Year!”)
</script>

[/CODE]
[COLOR=#ff0000][SIZE=3]
Variables[/SIZE][/COLOR]
• A Variable is a verbal representation of information that can be substituted for information.
• Before you can use a variable can be used in the code it has to be created using a variable declaration.


Variable Types

• Numeric variables- any number in standard or scientific notification
• String Variables – text (Must be in quotes)
• Boolean variables- TRUE/FALSE. Used when you want the program to act depending on condition
• Null Variables- a variable without an assigned value.



[COLOR=#ff0000][SIZE=3]Naming Rules[/SIZE][/COLOR]
• The first character must be a letter or an underscore
• The remaining characters must be letters, numbers or underscores
• Names cannot contain spaces
• JavaScript code items cannot be used as variable names.


[COLOR=#ff0000][SIZE=3]Variable Example[/SIZE][/COLOR]
---------------------------------------
var month ="March";
document.write(“School starts in” + Month);

OR

month = “March”;
document.write(“School starts in” + Month);
---------------------------------------
Both of the codes above will yield the same result. Which is: [COLOR="#FF0000"]School starts in March[/COLOR]



[COLOR=#ff0000][SIZE=3]Expressions and Operators[/SIZE][/COLOR]
• A JavaScript expression is a command that is used for assigning values to defined variables.
• A JavaScript operator is an element that can be used within an expression to perform and action, such as adding or combining multiple elements..
• The most commonly used operator is the equal sign (=) that will assign a value to the preceding variable.
• Another example of an operator is the plus sign (+) used for combining multiple elements.


[COLOR=#ff0000][SIZE=3]Assignment Operators
[/SIZE][/COLOR]• In JS, values are assigned to variables using assignment operators.
• An example is the equal sign (=)



[COLOR=#ff0000][SIZE=3]Functions[/SIZE][/COLOR]
• A function is a series of commands that can be executed by your program to calculate a value or perform an action


[COLOR=#ff0000][SIZE=3]Benefits of Funtions[/SIZE][/COLOR]
• Complex programming tasks can be broken down into simpler steps
• Code does not have to be duplicated within a program
• Code can be reused multiple times by a placing a simple function call anywhere is the program



[COLOR=#ff0000][SIZE=3]Declaration
[/SIZE][/COLOR]• A function has to be created using a function declaration like the one below


---------------------------------------
Function Name(Function Variables)
{
Function Commands;
}
---------------------------------------

[COLOR=#ff0000][SIZE=3]Three major parts of a function:[/SIZE][/COLOR]
Function Name= identifies each function
Parameters= Values needed by the function to produce the expected result
Commands= Actions that will be executed when the function runs.
Calling a function
Whenever you need to use the function you created you must insert this piece of code:
---------------------------------------
FunctionName(Variables);
---------------------------------------
(Replace "FuntionName" with the name you created for your function. Replace "Variables" with whatever variables you need to use)


[COLOR=#0000ff][SIZE=3]End of Chapter 1
[/SIZE][/COLOR]

[size=4][color=#0000ff]Chapter 2[/color]
[/size]


[SIZE=3][color=red]Arrays[/color][/size]

• In a typical computer program, data cannot be stored without the use of a database such as Access, Oracle, DB2 etc.

• Some of the program data, however, can be stored on a temporary basis by using data structures known as arrays.

• An array is a systematic arrangement of objects, usually is a rows and columns. Like a table./ single column table with a name assigned to it

[size=3][color=red]Array Example[/color][/size]
[size=3]--------------------------------------------[/size]
Var ArrayName= new Array(size);

ArrayName[index]= value;
ArrayName[index2]=value 2 ;

[size=3]--------------------------------------------[/size]

• The size is expressed as the number of elements that the array is going to contain.

• You can leave the size blank and have JavaScript automatically increase the array size as new elements are added.

• Index represents the row number




[SIZE=3][COLOR=#0000ff]Coming up:[/COLOR]
[COLOR=#0000ff][SIZE=2]
Loops
Objects/Events
Prompting user for input
Creating calculated fields
Validating user input[/SIZE][/COLOR][/SIZE] Edited by jumaji3
Updated some outdated information

Share this post


Link to post
Share on other sites
[quote name='milf hunter']Lol simple stuff.[/QUOTE]
Its a guide for beginners

Share this post


Link to post
Share on other sites
I would simply like to mention to use camelCasing for variables naming.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×