










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The document provides an overview of JavaScript as a high-level language used to add interactivity to web pages alongside HTML and CSS. It covers fundamental concepts like variables, data types, operators, conditionals, loops, and functions, and explores JavaScript’s use beyond the browser with Node.js for server-side development and frameworks like React Native for mobile apps. Modern JavaScript features (ES6 and beyond) are emphasized, along with setting up a coding environment using Visual Studio Code and helpful extensions like Prettier and Live Server. The document discusses dynamic typing, basic operations, arrays, objects, and best coding practices. It also covers DOM manipulation, explaining how JavaScript interacts with the Document Object Model to modify web content and handle events. Debugging techniques and practical exercises, such as building a BMI calculator and creating dynamic web pages, are included to reinforce learning.
Typology: Study Guides, Projects, Research
This document is temporarily unavailable for download
Available from 09/25/2024
2 documents
1 / 50
This page cannot be seen from the preview
Don't miss anything!











































This document is temporarily unavailable for download
High-Level Language : JavaScript is user-friendly, with many abstractions that keep us from worrying about complex operations like memory management. Object-Oriented : The language heavily relies on objects for data storage and operations. Multi-Paradigm : JavaScript's versatility allows for various programming styles, including imperative and declarative approaches.
React Angular Vue
alert ("Hello, world!");
Search for 'Default Formatter' Select 'esbenp.prettier-vscode'
Use the Go Live button in the bottom right corner of the status bar
Navigate to the provided URL: http://tinyurl.com/dh8hayp Click the 'Download' button and unzip the package on your computer Select and open the starter project folder in VS Code
...
...
Running Mathematical Calculations
Linking JavaScript to HTML (External File)
...
let firstName = "Andre"; console. log (firstName);
Utilizing Variables
Naming Convention Variables
Use camelCase for variable names, starting the first word with a lowercase letter and capitalizing subsequent words. Variables cannot start with a number and should only contain letters, numbers, underscores, or the dollar sign. Avoid using reserved JavaScript keywords like new or function as variable names.
Variable Naming Don'ts
Don't start variable names with an uppercase letter unless it's for a specific use case in object-oriented programming. Avoid using all-uppercase names for variables unless they are constants, like PI = 3.1415;, which are known to never change. Variable names cannot be the following names (which are reserved names):
this throw throws transient true try typeof var void volatile while with
// let firstName = "Andre"; /* let isAdult = true; let children; */
JavaScript is a **dynamically typed** language, meaning the type of a vari > "Dynamic typing is a concept in programming languages where the data typ This is evident in the following code: ```javascript **true** ; console. **log** ( **typeof** javaScriptIsFun); // "boolean" javaScriptIsFun = "YES!!"; console. **log** ( **typeof** javaScriptIsFun); // "string" **let** testVar; console. **log** ( **typeof** testVar); // "undefined" ## Comments in Code ## Comments are crucial for explaining the purpose of code sections or temporarily deactivating ## code without deletion. Single-line comments start with //. Multi-line comments are enclosed in /* */. ## D Undefined Variables ## When a variable is declared but not assigned a value, it is of type undefined. ## "Undefined is a special value in JavaScript that indicates a variable has been ## declared but has not yet been assigned a value." ## For example: console. **log** ( **typeof true** ); // "boolean" console. **log** ( **typeof** 23 ); // "number" **let** firstName = "Andre"; **let** lastName = "Silva"; console. **log** (firstName + lastName); // Outputs "AndreSilva" console. **log** (firstName + " " + lastName); // Outputs "Andre Silva" **let** x = 10 + 5 ; // 15 x += 10 ; // x = x + 10 = 25 console. **log** (x); x *= 4 ; // x = x * 4 = 100 console. **log** (x); **Concatenating Strings** The plus operator (+) can be used to concatenate strings, joining them together. Example: **Assignment Operators** The simple assignment operator (=) assigns a value to a variable. Compound assignment operators like +=, - =, *=, and /= combine an operation with assignment. Example: **Increment and Decrement Operators** The increment (++) and decrement (--) operators are used to increase or decrease a value by 1. Example: **let** currentYear = 2024 ; **let** birthYearAndre = 1986 ; **let** ageAndre = currentYear - birthYearAndre; console. **log** (ageAndre); // Outputs Andre's age **let** isFullAge = ageAndre >= 18 ; console. **log** (isFullAge) (ageAndre + ageSarah) / 2 ## Comparison Operators Used to compare values and return Boolean results (true or false). Example: ## D Operator Precedence ## Operator precedence defines the order in which operations are carried out in an expression. ## Understanding Operator Precedence A set of rules that determine the order in which operations are processed. The MDN precedence table is a valuable resource for understanding the precedence and associativity of JavaScript operators. ## Grouping Operator The grouping operator (()) has the highest precedence and is used to override the default precedence order. Example: ## Key Takeaways x++; x--; console. **log** (x); **const** firstName = 'Andre'; **const** birthYear = 1986 ; **const** job = 'teacher'; **const** year = 2024 ; // Current year for calculation **const** myNew = `I'm ${firstName}, a ${year - birthYear} year old ${job}!`; console. **log** (myNew); **const** age = 19 ; // Person's age **if** (age >= 18 ) { console. **log** ('Sarah can start driving license'); } **else** { **const** yearsLeft = 18 - age; console. **log** (`Sarah is too young. Wait another ${yearsLeft} years :)`); } ## Operator ## Description ## Strict equality operator (checks both value and type) ## Example: Creating a Person's Description ## D Taking Decisions: if/else Statements ## Introduction to if/else Statements ## if/else statements are used to control the flow of a program based on certain conditions. ## Definition: An if/else statement checks a condition and executes a block of code if ## the condition is true. If the condition is false, it can execute a different block of ## code. ## Example: Checking Eligibility for a Driver's License ## D Equality Operators: == vs. === ## The Strict Equality Operator (===) ## The strict equality operator compares both the value and the type of two operands. ## Operator ## Description ## Loose equality operator (performs type coercion) **The Loose Equality Operator (==)** ## The loose equality operator performs type coercion if needed. **Best Practices** Use the strict equality operator (===) to avoid unexpected results due to type coercion. **Example with Prompt** console. **log** (A && B); // Outputs: false console. **log** (A || B); // Outputs: true console. **log** (!A && B); // Outputs: true console. **log** (A || !B); // Outputs: false A AND B: This checks if both A and B are true. Since A is false, the result is false, regardless of B's value. A OR B: This checks if at least one of A or B is true. Since B is true, the result is true. NOT A AND B: This combines the true result of NOT A with B's true value, leading to true. A OR NOT B: This would be false because A is false and NOT B (the inversion of true B) is also false. ## Key Takeaways Boolean logic is a fundamental aspect of programming, enabling the manipulation of true and false values to make complex decisions. The **AND** operator requires both conditions to be true for a true result. The **OR** operator needs only one true condition for a true result. The **NOT** operator simply inverts a Boolean value's truth state. Combining these operators allows for nuanced logical expressions and decision- making in code. ## The switch Statement D ## The switch statement is an alternative way of writing a complicated if/else statement, especially ## when we want to compare one value to multiple different options. ## Example **let** day = 'Monday'; **switch** (day) { **case** "Monday": console. **log** ("Start the week with a jog"); console. **log** ("Stretching session in the evening"); **break** ; **case** "Tuesday": console. **log** ("High-intensity interval training (HIIT)"); **break** ; **case** "Wednesday": // ... } **switch** (expression) { **case** value1: // code to be executed if expression equals value **break** ; **case** value2: // code to be executed if expression equals value **break** ; default: // code to be executed if expression does not equal any of the above v } ## Let's consider a scenario where we have a variable day and for each day, there is a different ## activity planned. ## Note: The break statement is used to exit the switch block. If the value of day matches a case, ## the code within that case will be executed until a break statement is encountered.## D Switch ## Statements ## A switch statement is a type of control flow statement that allows the program to execute ## different blocks of code based on the value of a variable or expression. **Syntax and Usage** ## The syntax for a switch statement is as follows: **Example**