08.05.2017.
Monday.
Today we learned Javascript.
⟹Javascript introduction
➡Javascript statements are separated by semicolons.
➡Numbers are not allowed as the first charector.
➡All javascript identifiers are case sensitive.
⟹It has different cases
➡Hyphens - first-name, last-name
➡Underscore - first_name, last_name
➡Upper camel case (Pascal case) - FirstName, LastName
➡Lower camel case - firstName, lastName
⟹Javascript charactor set
➡Javascript uses the Unicode character set.
➡Unicode covers all the characters , punctuations , and symbols in the world.
⟹Javascript statements
➡Values➡Operaters
➡Expressions
➡key words
➡comments
Javascript statements are separated by semi colons.
Strings ⟹ "John Doe" or 'John Doe'
Variables are used to store data values.
var ⟹ Key word to declare variable.
= ⟹ Assign value to variable.
Arithmatic operaters ⟹ + , - , * , /
⟹Javascript comments
//I will be executed ⟹ Single line command
/* I will be executed.
I will be executed. */ ⟹ Multi line command
Numbers are not allowed the first charector.But first charector must be a letter or under score(_) or a doller sign($).
Javascript is a case sensitive
Example:firstname , firstName ⟹ There are not same values.
⟹Javascript can change
HTML content ⟹ Hi ➝ Hello
HTML attributes ⟹ Turn on ➝ Turn off
⟹Javascript display possibilities
1)Writing into an HTML elements using ⟹ inner.html()
2)Writing into an HTML elements using output ⟹ document.write()
3)Writing into an HTML elements using alert box ⟹ window.alert()
4)Writing into an HTML elements using browser console ⟹ console.log()
⟹JavaScript Data Types
JavaScript variables can hold many data types➡numbers
➡strings
➡objects
➡booleans
➡arrays
⟹JavaScript Functions
➡A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().➡Function names can contain letters,
digits,
underscores,
and dollar signs
(same rules as variables).
➡The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
➡The code to be executed, by the function, is placed inside curly brackets: {}
function name(parameter1, parameter2, parameter3) {
code to be executed
}
➡Function parameters are the names listed in the function definition.
➡Function arguments are the real values received by the function when it is invoked.
➡Inside the function, the arguments (the parameters) behave as local variables.
⟹Function Invocation
➡The code inside the function will execute when "something" invokes (calls) the function:➡When an event occurs(when a user clicks a button)
When it is invoked from JavaScript code
Automatically
⟹Function Return
➡When JavaScript reaches a return statement, the function will stop executing.➡If the function was invoked from a statement, JavaScript will "return" to execute the code after the invoking statement.
➡Functions often compute a return value. The return value is "returned" back to the "caller"
var x = myFunction(4, 3); // Function is called, return value will end up in x function myFunction(a, b) {
return a * b; // Function returns the product of a and b }
⟹Why we use functions
You can reuse code:Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
⟹The () Operator Invokes the Function
Using the example above, toCelsius refers to the function object, and toCelsius() refers to the function result.Accessing a function without () will return the function definition instead of the function result:
JavaScript Objects
⟹Object Properties
The name:values pairs (in JavaScript objects) are called properties.var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
⟹Accessing Object Properties
You can access object properties in two ways:objectName.propertyName
objectName["propertyName"]
⟹Accessing Object Methods
You access an object method with the following syntax:objectName.methodName()
No comments:
Post a Comment