5. JavaScript Alerts
● The alert() method displays an alert box with an specified message as entered by the
programmer along with an OK button.
● An important note here is that the method should not be overused because it
prevents the user from getting access to the other parts of the page until the box is
closed.
● The syntax for the same is : alert(message)
6. JavaScript Alerts
● By opening VS Code create an HTML file called “jstutorial.html” by adding the
boilerplate.
● Give a title and name it JavaScript Tutorial.
● Now create a file called “tutorial.js” and type in a sample alert message.
● Save the file and copy and paste the path of the file in your favorite browser window
and observe the output.
● You will be able to observe “JavaScript Tutorial” being displayed on the screen only
when you click “OK” on the alert box.
7. Variables
● Var
a.Globally scoped method to create variables.
b.If the same variable is defined outside any function globally as well as in any
function or condition, it causes conflicts.
● let and const
a.‘let’ lets us to reassign values.
b.const does not let us reassign values once declared.
8. Datatypes
● There are six types of primitive datatypes:-
a.Strings
b.Numbers
c. Boolean
d.Null
e.Undefined
f. Object
● These are directly assigned to memory, that is, you don’t have to
explicitly include the data type.
9. ● Lets the user select the code for a given set of conditions.
● They are defined using logical operators.
● The Conditionals are:-
○ Double equals with if-else
○ Triple equals with if-else
○ Other logical operators with nested if-else ladder.
Conditionals
A little into conditionals!
10. ● As the name suggests it keeps executing a set of code until a condition is
reached.
● The loops are:-
○ for loop
○ while loop
Loops
12. Functions
What are Functions?
● A block of organized code that could be reused to perform actions based on the
arguments (input) passed into it.
● The parts of a function are:
a.Function Definition
b.Function Call
● The Arrow Function was introduced in ES6 Version for better readability and
faster development. The same function can be written as an arrow function.
13. Functions
● Functions basically divide the code so that each function deals with a specific task.
● Each function describes the particular task that it does so that it becomes very
easy in order to debug.
● Debugging can be done one function at a time.
● The other big advantage is that the functions are reusable.
● After the function name we can put a pair of parentheses and they would contain
one or more parameters specified separated by commas.
● The names of these parameters are being chosen by the programmer its
datatype is preceded by it.
14. Arrays
● A collection of similar data type variables
● Unlike other languages, JavaScript gives us the freedom of using different data
types and also we don't have to define the length of the array to initialise it
● Defined using square brackets
● Arrays always start from zero.
● The array could be manipulated even though it is defined as a const variable but it
cannot be reassigned.
15. Object Literals
● They are basically key-value pairs.
● Many key-value pairs are defined under one variable.
● A good way of understanding this is by taking a look at “package.json” as an
example.
● All members of an object literal in JavaScript, both properties and functions, are
public. The only place you can put private members is inside of a function.
● Object literal should be used if you want to create objects on the go with no
intention of copying values to another object or maybe mapping one object to
another.
16. Higher-Order Array Methods
● The for-each method
a.Used to iterate through all the elements of the array.
● The map method
a.Used to iterate through all the elements of the array
b.Similar to forEach Method but it also returns the new array with all the
new values
● The filter method
a.As the name suggests, it is used to return the elements of an array the
satisfy a certain condition.