An Algorithm Is A Process or Set of Rules To Be Followed in Calculations or Other Problem-Solving
An Algorithm Is A Process or Set of Rules To Be Followed in Calculations or Other Problem-Solving
operations. It could mean either a desktop or laptop computer (PC, Mac), a computing server, or a
mobile device like a tablet or smartphone.
A computer often requires human intervention. That’s where programmers and developers come in!
They write programs that result in instructions to a computer.
• A computer program (also called an application or software) usually comprises one or more
text files containing commands in the form of code. This is why developers are also called
coders.
• A programming language is a way to give orders to a computer. It’s a bit like a human
language! Each programming language has vocabulary (keywords that each play a specific
role) and grammar (rules defining how to write programs in that language).
Long story short:
• A computer is a machine whose role is to execute quickly and flawlessly a series of actions
given to it.
• A program is a list of actions given to a computer. These actions take the form of textual
commands. All these commands form the program’s source code.
• The programmer’s task is to create programs. To accomplish this goal, he can use different
programming languages.
• Before writing code, one must think ahead and decompose the problem to be addressed in a
series of elementary operations forming an algorithm
An algorithm is a process or set of rules to be followed in calculations or other problem-solving
operations, especially by a computer.
he main properties of an algorithm which we will now consider:
1.Input
An algorithm must possess 0 or more well-defined inputs supplied externally to the algorithm.
2. Output
An algorithm should have 1 or more well-defined outputs as desired.
3. Correctness
Every step of the algorithm must generate a correct output.
4. Definiteness
Algorithms should be clear and unambiguous, thus every step of the algorithm should be clear and
well defined.
5. Finiteness
The algorithm should have a finite number of steps that must be carried out to achieve the task at
hand.
every single step of the algorithm has to generate a correct output as long as the main output is
correct.
JavaScript is the most widely used scripting language on Earth. It has the largest library ecosystem
of any programming language.
JavaScript is the core language of the web, and the only programming language that can run in all
major web browsers.
The programs in JS are called scripts. They can be written right in a web page’s HTML and run
automatically as the page loads.
do everything related to webpage manipulation, interaction with the user, and the webserver.
For instance, in-browser JavaScript is able to:
• Add new HTML to the page, change the existing content, modify styles.
• React to user actions, run on mouse clicks, pointer movements, key presses.
• Send requests over the network to remote servers, download and upload files (so-called
AJAX and COMET technologies).
• Get and set cookies, ask questions to the visitor, show messages.
ECMA6 This version brings a lot of interesting novelties to the table. It is now well supported by
most environments and platforms, starting with web browsers
When JavaScript was created, it initially had another name: "LiveScript". But Java was very
popular at that time, so it was decided that positioning a new language as a “younger brother”
of Java would help. But as it evolved, JavaScript became a fully independent language with its own
specification called ECMAScript ,and now it has no relation to Java at all.
There are several methods to make JavaScript output and/or grab data (from the user). They either
modify or replace existing HTML, help to debug, or retrieve HTML content.
Alert() prompt() confirm()
alert() displays an alert box.prompt() stores the input from a user in a variable. confirm() returns
true if the user clicks on Ok, and false if he clicks on Cancel
You should use the console.log() method to print to console your JavaScript. The
JavaScript console log function is mainly used for code debugging as it makes the JavaScript
print the output to the console.
JavaScript, there are six primitive types:
1. boolean (true or false)
2. number (including integers like 1, -2, and floating point numbers like 3.14, 2e-3)
3. string ( Strings are used for storing text. Strings must be inside of either double or single
quotes.)
4. null (null has one value: null. It is explicitly nothing.)
5. undefined (A variable that has no value is undefined)
6. Symbol (don’t worry about them yet)
console.log(typeof(true)) // prints boolean
var x;
console.log(Boolean(x)); //false
var x = 5;
var y = "5";
console.log(x != y); //false
the logical operators AND and OR in JavaScript, they do not return true or false!
The shorthand assignment operator (+=) can also be used to concatenate strings.
Template Strings:
Template Strings use backticks (`` ) rather than the single or double quotes we're used to with
regular strings.
One of their first real benefits is string substitution. Substitution allows us to take any valid
JavaScript expression (including say, the addition of variables) and insert it inside a Template
Literal using the ${} syntax, the result will be output as part of the same string.
var name = "Lucy";
console.log(`Yo, ${name}!`) // prints “Yo, Lucy!”
A function is basically a piece of code which can be reused
without having to write it again and again.
Think of a function like a mathematical function giving you a
relationship between input and output variables. If you don’t like
maths, think of a function like a vending machine. You give it
some coins and a number, and it spits out some cold soda.
The function definition example in the code box describes the relationship between its input
variables a and b, and the return value of the function.
The return statement returns the value of the function. When calling the add function with
arguments a and b, it computes the value a+b and returns it.
User-Defined Functions
Function declarations:
In most programming and scripting languages, there are some built-in functions that are kept in a
library. The real interesting part though, is that we can write our own functions, (also called 'User
Defined Functions' or 'UDF'.) to perform specialized tasks.
Before using a function, we must first define it somewhere in the scope from which we wish to call
it. Defining your own function in JavaScript is a simple task.
A classical function declaration begins with the keyword function, followed by:
function Parameters
Parameters are variables listed as a part of the function definition.
Arguments are values passed to the function when it is invoked.
In JavaScript, parameters of functions default to undefined. Default function parameters allow
named parameters to be initialized with default values if no value or undefined is passed.
var add = function( a, b ) {
return a + b;
}
console.log(add(0,1)) // prints 1
console.log(add()) // prints NaN
console.log(add())
/* prints 1 even though no arguments were given to this function call */
names
listed in the function
definition
Function
arguments
are the real
values
passed to (and received by) the function at the
execution
“Calling”, “Invoking” or “Executing” are terms used
interchangeably when executing a predefined function. Functions
can be called using their references (((≃ their names))). And
necessary arguments are passed to the function during this phase
(see code box).
Note: When a function does not return anything, its return value becomes undefined
break exits the closest loop it is in, and continues with the next
command.
• continue skips out from the loop body, and jumps back to the condition of the loop.
Whenever i is even, continue moves execution back to the next iteration of i in
numbers.
We can delete any element from the array. The value undefined will be placed in place of this
element.
arr.indexOf(0) and arr.indexOf(1) return respectively, if arr holds the array [1, 5, 8]?
-1 and 0