Professional Documents
Culture Documents
CSPC223 Modules 1 and 2 Reviewer
CSPC223 Modules 1 and 2 Reviewer
CSPC223 Modules 1 and 2 Reviewer
MODULE 01
JavaScript
Brendan Eich
Hired by the Netscape corporation, and tasked to develop a new language for their product,
the Netscape Navigator web browser which was called LiveScript
node.js
This technique consists of compiling code fragments during the execution of the program
(more than a single instruction) and allows you to increase its performance.
Client-side Programming
Back-end Programming
Code Obfuscation
consists of transforming our ready script into a slightly less readable form
Dynamic Typing
consists of the fact that we can store data of any type in a variable (a variable is a container in
which we store the data we will use).
Static Typing
A variable can only contain one type of variable (e.g. numbers) during program execution.
REQUIREMENTS OF PROGRAMMING
❖ Code editor
❖ Compiler or interpreter
❖ Debugger
➢ a tool that allows us, among other things, to pause the program in the indicated place
and analyze its current state
Online Environments
Local Environments
❖ Package Managers
enabling the management of libraries (containing ready-made solutions that we can use in
our programs) or components of the development environment
e.g. npm or yarn
❖ Task Runners and Module Bundlers
used, in simple terms, to automate the process of software development and merge the
resulting code from many files and libraries
e.g. Grunt or Webpack
❖ Testing Framework
allows for automatic testing of the correctness of our program in search of potential errors
e.g. Mocha, Jasmine, or Jest
❖ Security Analyzers
as you can guess, used to control the security of our solution
e.g. Snyk, RetireJS, or OWASP Dependency Check
Code Editor
Powerful code editor free for both personal and commercial use. It has quickly become one of
the favorites when it comes to web development. It has built-in features like a JavaScript debugger,
and tools to streamline web projects. It’s also highly customizable via the extension system (there are
many additions dedicated especially to the JavaScript language).
2. Sublime Text
Fast and easy-to-use code editor with many advanced features, like multiple-line editing, fast
search, and others. A trial version is available, but for long-term usage, a license needs to be purchased
for both private and commercial use.
3. Notepad++
Free and lightweight code and text editor. The program is small and fast, supports dozens of
programming languages, and can be extended with plugins. It may be old and ugly, but it’s still sharp.
Interpreter
Debugger
a tool that allows you to slow down or even halt the execution of a program, run instructions step
by step, and look at and analyze the state of the program at any given moment.
Browser Developer Tools:
o the inspector
▪ which will allow us, for example, to analyze the individual HTML elements of an
open website;
o the JavaScript console
▪ which firstly shows all the information about the errors, and secondly allows us to
run single JavaScript commands in the context of the current page;
o the debugger
▪ which, among other things, shows the current values of variables, and allows you
to pause code execution in the indicated place and to perform step-by-step work
(i.e. execute single instructions of the program).
The "Hello, World!" Program
The phrase that was used a long time ago in a very important book about the C language that
marks someone as learning a new programming language for almost 50 years.
Console
a place where various messages are displayed, normally invisible to the browser user.
Function
a piece of code that allows you to perform a specific task such as displaying something on the
console
Method
Client-side JavaScript
a language of the web and exists only in the web ecosystem wherein its code needs to be
embedded in an HTML document.
a set of tags used to describe the structure of a website that allows us to give a page the
format of a document containing sections, headers, paragraphs, lists, and the like.
<!DOCTYPE html>
o This is not a typical tag, as it is used to inform the browser that the whole document has
been prepared according to HTML5.
<head>
o contains additional information about the document
<title>
o sets the title of the page mostly visible in the browser title bar.
Defer Async
means that the script should be means that the script will be executed
executed after the whole page is loaded; immediately, but in parallel to parsing
the rest of the page.
a language used together with HTML to describe the appearance of a page and its elements.
Constant
used to store certain values, but once values have been entered into them during initialization,
they can no longer be modified
ReferenceError
it doesn’t know a variable by this name (so the variable itself is undefined).
𝒗𝒂𝒓
allows you to re-declare a variable, which can potentially lead to errors in the program execution.
𝒍𝒆𝒕
declare variables, if only because you don't want to accidentally declare a variable again.
Initialization
"𝒖𝒔𝒆 𝒔𝒕𝒓𝒊𝒄𝒕";
used when we want to force the interpreter to behave according to modern JavaScript standards.
Indentation
Variable shadowing
Hoisting
refers to the built-in behavior of the language through which declarations of functions, variables,
and classes are moved to the top of their scope – all before code execution.
DATA TYPES
A. Primitive
➢ a type of data whose values are atomic which means that the value is one, indivisible element.
1. Boolean
2. Number
main numeric type in JavaScript that represents both real numbers (e.g. fractions) and
integers.
allow for all typical arithmetic operations, like addition, subtraction, multiplication, and
division.
Range: −(253 − 1) 𝑡𝑜 (253 − 1)
Prefixes:
o 0𝑥 = ℎ𝑒𝑥𝑎𝑑𝑒𝑐𝑖𝑚𝑎𝑙 = 0𝑥
o 0𝑜 = 𝑜𝑐𝑡𝑎𝑙
o 0𝑏 = 𝑏𝑖𝑛𝑎𝑟𝑦
o 𝑒3 = 𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡𝑖𝑎𝑙 𝑓𝑜𝑟𝑚 = 123𝑒 − 5 → 0.00123, 9𝑒3 → 9000
Three additional special values:
o Infinity
1
▪ , 𝑎𝑛𝑦 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑑𝑖𝑣𝑖𝑑𝑒𝑑 𝑡𝑜 0
0
o -Infinity
1
▪ − 0 , 𝑎𝑛𝑦 𝑛𝑒𝑔𝑎𝑡𝑖𝑣𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑑𝑖𝑣𝑖𝑑𝑒𝑑 𝑡𝑜 0
3. BigInt
5. Symbol
doesn't have any literal value and can only be created using a special constructor function.
a form of identifier that are guaranteed to be unique.
6. Undefined
the default value that all variables have after a declaration if no value is assigned to them
B. Complex
1. Array
2. Object
Operator
a symbol or name that represents some action to be performed on the indicated arguments.
+ 𝒔𝒚𝒎𝒃𝒐𝒍
o a two-argument operator representing summation.
𝒕𝒚𝒑𝒆𝒐𝒇 𝒐𝒑𝒆𝒓𝒂𝒕𝒐𝒓:
o unary: takes only one argument
o informs us of the type of data indicated as a given argument
o "undefined", "object", "boolean", "number", "bigint", "string", "symbol", "function"
Null
value itself is primitive, while the type to which it belongs is not a primitive type
used to indicate that the variable does not contain anything, and most often it is a variable that
is intended to contain values of complex types.
Constructor Functions
String: 𝑆𝑡𝑟𝑖𝑛𝑔();
o by default create and return an empty string – primitive "";
Number: 𝑁𝑢𝑚𝑏𝑒𝑟();
o by default create and return the value 0;
Boolean: 𝐵𝑜𝑜𝑙𝑒𝑎𝑛();
o by default create and return the value of false.
o False: 0, NaN, empty string, undefined, null
o True: any value
BigInt: 𝑆𝑡𝑟𝑖𝑛𝑔();
o requires you to pass some initial value to it
HTML: SYNTAX
Empty page
<!DOCTYPE html>
<html>
<head>
<title>Empty Page</title>
</head>
<body>
</body>
</html>
JAVASCRIPT: SYNTAX
Displaying message
Declaring variables
𝑣𝑎𝑟 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑁𝑎𝑚𝑒;
𝑙𝑒𝑡 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑁𝑎𝑚𝑒;
𝑐𝑜𝑛𝑠𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒;
Initializing variables
𝑐𝑜𝑛𝑠𝑜𝑙𝑒. log(𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑁𝑎𝑚𝑒) ;
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑁𝑎𝑚𝑒 = "𝑛𝑒𝑤𝐷ata";
Program block
Declaring function
𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑡𝑒𝑠𝑡𝐹𝑢𝑛𝑐𝑡𝑖𝑜𝑛() {
𝑐𝑜𝑛𝑠𝑜𝑙𝑒. 𝑙𝑜𝑔("𝐻𝑒𝑙𝑙𝑜");
𝑐𝑜𝑛𝑠𝑜𝑙𝑒. 𝑙𝑜𝑔("𝑊𝑜𝑟𝑙𝑑");
Function call
𝑡𝑒𝑠𝑡𝐹𝑢𝑛𝑐𝑡𝑖𝑜𝑛();
DATA TYPES
Boolean
Number
A. Decimal
𝑙𝑒𝑡 𝑎 = 10; // 10
B. Hexadecimal
𝑙𝑒𝑡 𝑏 = 0𝑥10 // 16
C. Octal
𝑙𝑒𝑡 𝑐 = 0𝑜10; // 8
D. Binary
𝑙𝑒𝑡 𝑑 = 0𝑏10; // 2
BigInt (𝑛𝑢𝑚𝑏𝑒𝑟𝑠 𝑤𝑖𝑡ℎ 𝑡ℎ𝑒 … 𝑛 𝑠𝑢𝑓𝑓𝑖𝑥)
String
𝑙𝑒𝑡 𝑚𝑒𝑠𝑠𝑎𝑔𝑒 = ′𝑇ℎ𝑒 𝑣𝑒𝑠𝑠𝑒𝑙 \′ 𝑀𝑎𝑟𝑠\′ 𝑐𝑎𝑙𝑙𝑒𝑑 𝑎𝑡 𝑡ℎ𝑒 𝑝𝑜𝑟𝑡.′ ; → 𝑇ℎ𝑒 𝑣𝑒𝑠𝑠𝑒𝑙 ⬚′𝑀𝑎𝑟𝑠 ′ 𝑐𝑎𝑙𝑙𝑒𝑑 𝑎𝑡 𝑡ℎ𝑒 𝑝𝑜𝑟𝑡.
Addition Operation
String Interpolation
Undefined
𝑙𝑒𝑡 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑁𝑎𝑚𝑒;
Implicit Conversions
Length
charAt()
Object
𝑙𝑒𝑡 𝑡𝑒𝑠𝑡𝑂𝑏𝑗 = {
𝑛𝑟: 600,
𝑠𝑡𝑟: "𝑡𝑒𝑥𝑡"
};
Array
a two-argument operator, which requires the tested variable (or literal) and object class to be
specified.