reading-notes

View project on GitHub

Read06

Return to home page.

Introduction to javascript:

JavaScript can be used in browsers to make websites more interactive, interesting, and user-friendly you will need to know how to build web pages using HTML and CSS. Beyond that, no prior experience with programming is necessary.

  • Learning to program with JavaScript involves:

1- Understanding some basic programming concepts and the terms that JavaScript programmers use to describe them.

2- Learning the language itself, and, like all languages, you need to know its vocabulary and how to structure your sentences.

3- Becoming familiar with how it is applied by looking at examples of how JavaScript is commonly used in websites today.

How does Javascript makes pages more interactive:

1- ACCESS CONTENT: You can use JavaScript to select any element, attribute, or text from an HTML page.

2- MODIFY CONTENT: You can use JavaScript to add elements, attributes, and text to the page, or remove them.

3- PROGRAM RULES: You can specify a set of steps for the browser to follow (like a recipe), which allows it to access or change the content of a page.

4- REACT TO EVENTS: You can specify that a script should run when a specific event has occurred.

The ABC of programming:

What is a script and how do I create one?

A script is a series of instructions that a computer can follow to achieve a goal.

  • WRITING A SCRIPT: 1- To write a script, you need to first state your goal and then list the tasks that need to be completed in order to achieve it.

2- Start with the big picture of what you want to achieve, and break that down into smaller steps.

Designing a script:

1- Tasks: Once you know the the goal of your script, you can work out the individual tasks needed to achieve it.

2- Each individual task may be broken down into a sequence of steps, when you are ready to code the script, these steps can be translated into lines of code.

Expressions & Operators:

Expressions:

An expression evaluates into (results in) a single value. Broadly speaking there are two types of expressions:

1- EXPRESSIONS THAT JUST ASSIGN A VALUE TO A VARIABLE.

2- EXPRESSIONS THAT USE TWO OR MORE VALUES TO RETURN A SINGLE VALUE.

Operators:

Expressions rely on things called operators; they allow programmers to create a single value from one or more values.

  • There are several types of operators such as:

1- ASSIGNMENT OPERATORS: Assign a value to a variable.

2-ARITHMETIC OPERATORS: Perform basic math.

  • ORDER OF EXECUTION: Several arithmetic operations can be performed in one expression, but it is important to understand how the result will be calculated. Multiplication and division are performed before addition or subtraction.

3-STRING OPERATORS: Combine two strings.

There is just one string operator: the+ symbol, It is used to join the strings on either side of it.

FUNCTION:

WHAT IS A FUNCTION?

Functions let you group a series of statements together to perform a specific task. If different parts of a script repeat the same task, you can reuse the function (rather than repeating the same set of statements).

Declaring a function:

To create a function, you give it a name and then wright the statements needed to achieve its task inside the curly braces, this is called decraling a function.

Calling a function:

Having declared the function, you can execute all the statements inside it using only one line of code, this is called calling a function.

Declaring a function that need information:

sometimes a function needs specific information to perform its task, in such cases you need to add the parameters when you declare the function, inside the function the parameters act like variables.

Calling a function that need information:

When you call the function that has parameters, you specify the value it should use in the parantheses that follows it’s name, the values are called arguments.