JAVA SCRIPT
How js makes web pages more interactive
- Access contact
- You can use JavaScript to select any element, attribute, or text from an HTML page
- Modify content
- You can use JavaScript to add elements, attributes, and text to the page, or remove them.
- 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.
- React to event
- You can specify that a script should run when a specific event has occurred.
Being able to change the content of an HTML page while it is loaded in the browser is very powerful. The examples below rely on the ability to:
Access the content of the page Modify the content of the page Program rules or instructions the browser can follow React to events triggered by the user or browser
-
Before you learn how to read and write the JavaScript language itself, you need to become familiar with some key concepts in computer programming.
- What is a script and how do I creat one?
- A script is a series of instructions that the computer can follow in order to achieve a goal.
- Each time the script runs, it might only use a subset of all the instructions.
- Computers approach tasks in a different way than humans, so your instructions must let the computer solve the task prggrammatically.
- To approach writing a script, break down your goal into a series of tasks and then work out each step needed to complete that task (a flowchart can help).
- EXPRESSIONS
An expression evaluates into (results in) a single value. Broadly speaking there are two types of expressions.
- EXPRESSIONS THAT JUST ASSIGN A VALUE TO A VARIABLE
- 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.
WHAT IS A FUNCTION IN JAVASCRIPT?
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 st atements).