reading-notes

View project on GitHub

JAVA SCRIPT

IMG

How js makes web pages more interactive

  1. Access contact
    • 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 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.

  1. 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).

img

  1. 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
  2. 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?

img

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).