0% found this document useful (0 votes)
36 views27 pages

Web x.0

The document provides an overview of the Semantic Web Stack, which includes layers such as URI, XML, RDF, OWL, and SPARQL, aimed at enhancing web content interoperability and processing. It also discusses clickstream analysis, detailing its applications in understanding user behavior on websites and improving content strategies. Additionally, it covers TypeScript, including its execution on different operating systems, data types, and user-defined types like arrays, tuples, interfaces, and classes.

Uploaded by

darshhtp69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views27 pages

Web x.0

The document provides an overview of the Semantic Web Stack, which includes layers such as URI, XML, RDF, OWL, and SPARQL, aimed at enhancing web content interoperability and processing. It also discusses clickstream analysis, detailing its applications in understanding user behavior on websites and improving content strategies. Additionally, it covers TypeScript, including its execution on different operating systems, data types, and user-defined types like arrays, tuples, interfaces, and classes.

Uploaded by

darshhtp69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IA-Ques

Module 1- Introduc

Q. Explain Semantic Web Stack?

The "Semantic Web Stack" refers to a conceptual framework for understanding and implementing technologies
that enable the Semantic Web. The Semantic Web is an extension of the World Wide Web that aims to make web
content more understandable by computers, allowing them to process and interpret information in a meaningful
way.

The Semantic Web Stack typically consists of several layers, each building upon the others to achieve its goals:

1. **URI (uniform Resource Identifier)**:

At the base of the stack is the concept of URIs, which uniquely identify resources on the web. URIs serve as the
foundation for linking and referencing data across the web.

2. **XML (eXtensible Markup Language)**:

XML provides a standardized format for structuring and encoding data on the web. It allows information to be
organized hierarchically and tagged with metadata, making it easier for computers to understand and process.

3. **RDF (Resource Description Framework)**:

RDF is a data model used to describe resources and their relationships on the web. It represents information in
the form of triples (subject-predicate-object), enabling the creation of rich, interconnected datasets.

4. **OWL (Web Ontology Language)**:

OWL is a language for defining ontologies, which specify the concepts and relationships within a particular
domain. Ontologies provide a formal framework for representing knowledge and enabling automated reasoning
about data.

5. **SPARQL (SPARQL Protocol and RDF Query Language)**:

SPARQL is a query language and protocol for querying RDF data. It allows users to retrieve and manipulate
information stored in RDF datasets, enabling powerful search and analysis capabilities across the Semantic Web.
By leveraging technologies across these layers, the Semantic Web aims to enhance the interoperability,
discoverability, and interpretability of web content, ultimately enabling more intelligent and efficient information
processing on the internet.

Q. What is click stream analysis and its applications?


In website analytics, a clickstream or click path is the sequence of pages a user visits on a website.
Thus, clickstream analysis is simply the process of analyzing what pages a user visits (and in what
order) on a website. This allows webmasters to better understand how their website is being used,
and where they can make improvements.

Often, clickstream analysis factors in various analytics, such as user or session analytics, to compare
how different groups of users interact with the same website. User analytics, like the user’s gender
(if that data is available), allow webmasters to see how their content appeals to different audiences.
Session analytics, like how the user reached the website, allow webmasters to compare their traffic
sources.

Clickstream analysis works by collec


proper
track user behavior over .
Once the data is collected, it is analyzed using data analy
and trends in user behavior. This analysis can include visualiz
help businesses understand how users are interac

In add
clickstream analysis to gain insights into user behavior on third-party sites and pl
example, businesses can analyze user behavior on social media pl
marketplaces to id

Comparing traffic channels

Webmasters can use clickstream analysis to compare traffic channels if they know how their users
first reached the website. With most website analytics tools, webmasters will have this information;
for example, whether a given user reached the website through a search engine, social media, or by
typing the website’s URL into their browser.

From the clickstream data itself, a webmaster may be able to identify that users from certain
channels view more or less pages, on average. For example, they may notice that users from search
engines view twice as many pages as users from social media. As a result of this, the webmaster may
choose to focus more resources on the former channel.

Comparing advertising strategies

Webmasters that use paid advertising to drive visitors to their website can go one step further and
compare individual advertising strategies. Just like before, a webmaster can compare how users
from various advertising media interact with their website, to see where advertising is most
effective.
Sometimes. clickstream data may also include information about what actions users take, and not
just what pages they visit. If this is the case, websites like online shops may choose to compare
various advertising strategies against the number of sales made through them, and not the number
of pages visited.

Improving existing content

Clickstream analysis can still be incredibly powerful, even without session analytics. By looking at the
path users take through a website, webmasters are able to see where users “drol ojj”. With this
information, they can choose to improve the pieces of content which caused users to leave the
website.

Interlinking between existing content

Similarly, clickstream data alone can be used to interlink between existing content. Interlinking is
simply the process of linking between pages on the same website. With clickstream data,
webmasters can identify pages with few links (as more users might be leaving the website on those
pages) and add more of them.

Q5. Write a note on RDF?


RDF: RDF, or Resource Description Framework, is a standard model for data interchange on the
web. It provides a way to describe resources and their relationships in a machine-readable format.
In short:

1. Resource: Anything that can be identified by a URI.


2. Triple: Basic building block consisting of a subject, predicate, and object (e.g., "Alice knows Bob").
3. Subject: The resource being described.
4. Predicate: Describes the relationship between the subject and the object.
5. Object: The value or another resource related to the subject.

RDF enables the creation of semantic graphs, where nodes represent resources and edges
represent relationships, facilitating the integration and exchange of data across diverse
applications and domains.

Write one example of SQARQL:


SPARQL PROTOCOL AND RDF QUERY LANGUAGE: WORKS WITH RDF FORMAT TO MANIPULATE DATA IN DATABASE
 PREFIX dc: <[Link]

SELECT ?title WHERE { ?book dc:title ?title . }

In this query:

 The PREFIX declaration establishes a namespace prefix ( dc ) for the Dublin Core metadata terms.
 The SELECT statement specifies that we want to retrieve the ?title of the books.
 The WHERE clause defines the pattern to match in the dataset. It specifies that for each ?book, we
want to retrieve its dc:title.

When executed against a dataset containing RDF data about books, this query would return a list
of all book titles available in the dataset.
Module:02 Typescript
[Link] how the typescript program can be executed on windows/Linux OS?
TypeScript is an open-source programming language. It is developed and maintained by Microsoft.
TypeScript follows JavaScript syntactically but adds more features to it. It is a superset of
JavaScript. In order to execute or run any typescript file, first you need to install node and using it
install typescript globally in your local system.
Syntax:
To check node is installed, run command if not you have to installed it first:
node -v
Now to install typescript, use:
npm install -g typescript
After installing typescript, create a .ts file, for example, [Link] as given below:
Example:

var greet: string = "Greetings";


var geeks: string = "GeeksforGeeks";
[Link](greet + " from " + geeks);
// save the file as [Link]

Output:
Greetings from GeeksforGeeks
Procedure 1: This typescript file [Link] will create a javascript file at runtime with the same
name. To run any typescript file there are a few ways: Syntax:
Step 1: First, run the typescript file with the following command. This will create a
javascript file from typescript automatically with the same name.
tsc [Link]
Step 2:Now run the javascript file, the [Link] file will get executed:
node [Link]
Procedure 2: You can merge both the commands by using a pole | and && like below : Syntax:
In Windows:
tsc [Link] | node [Link]
In Linux or MacOS:
tsc [Link] && node [Link]
Procedure 3: You can also install ts-node along with typescript using the following
command: Syntax:
To install:
npm install -g ts-node
To run:
ts-node [Link]
Output: Using any of the three ways, the output will remain the same.
Greetings from GeeksforGeeks

Q3. Explain typecript types?

The TypeScript language supports different types of values. It provides data types for the JavaScript
to transform it into a strongly typed programing language. JavaScript doesn't support data types, but
with the help of TypeScript, we can use the data types feature in JavaScript. TypeScript plays an
important role when the object-oriented programmer wants to use the type feature in any scripting
language or object-oriented programming language. The Type System checks the validity of the
given values before the program uses them. It ensures that the code behaves as expected.

TypeScript provides data types as an optional Type System. We can classify the TypeScript data type
as following.
1. St

In the context of type systems, static types mean "at compile time" or "without running a program."
In a statically typed language, variables, parameters, and objects have types that the compiler knows
at compile time. The compiler used this information to perform the type checking.

Static types can be further divided into two sub-categories:

ADVERTISEMENT

Built-in or Primitive Type

The TypeScript has five built-in data types, which are given below.

Number
Like JavaScript, all the numbers in TypeScript are stored as floating-point values. These numeric
values are treated like a number data type. The numeric data type can be used to represents both
integers and fractions. TypeScript also supports Binary(Base 2), Octal(Base 8), Decimal(Base 10), and
Hexadecimal(Base 16) literals.

Syntax:

1. let identifier: number = value;

Examples:-

1. let first: number = 12.0; // number


2. let second: number = 0x37CF; // hexadecimal
3. let third: number = 0o377 ; // octal
4. let fourth: number = 0b111001; // binary
5.
6. [Link](first); // 123
7. [Link](second); // 14287
8. [Link](third); // 255
9. [Link](fourth); // 57

String

We will use the string data type to represents the text in TypeScript. String type work with textual
data. We include string literals in our scripts by enclosing them in single or double quotation marks.
It also represents a sequence of Unicode characters. It embedded the expressions in the form of $
{expr}.

Syntax

ADVERTISEMENT
ADVERTISEMENT

1. let identifier: string = " ";


2. Or
3. let identifier: string = ' ';

Examples

1. let empName: string = "Rohan";


2. let empDept: string = "IT";
3.
4. // Before-ES6
5. let output1: string = employeeName + " works in the " + employeeDept + " department.";
6.
7. // After-ES6
8. let output2: string = `${empName} works in the ${empDept} department.`;
9.
10. [Link](output1);//Rohan works in the IT department.
11. [Link](output2);//Rohan works in the IT department.

Boolean

The string and numeric data types can have an unlimited number of different values, whereas the
Boolean data type can have only two values. They are "true" and "false." A Boolean value is a truth
value which specifies whether the condition is true or not.

Syntax

1. let identifier: BooleanBoolean = Boolean value;

Examples

1. let isDone: boolean = false;

Void

A void is a return type of the functions which do not return any type of value. It is used where no
data type is available. A variable of type void is not useful because we can only assign undefined or
null to them. An undefined data type denotes uninitialized variable, whereas null represents a
variable whose value is undefined.

Syntax

1. let unusable: void = undefined;

Examples

1. 1. function helloUser(): void {


2. alert("This is a welcome message");
3. }
1. 2. let tempNum: void = undefined;
2. tempNum = null;
3. tempNum = 123; //Error

Null
Null represents a variable whose value is undefined. Much like the void, it is not extremely useful on
its own. The Null accepts the only one value, which is null. The Null keyword is used to define the
Null type in TypeScript, but it is not useful because we can only assign a null value to it.

Examples

1. let num: number = null;


2. let bool: boolean = null;
3. let str: string = null;

nndefined

The Undefined primitive type denotes all uninitialized variables in TypeScript and JavaScript. It has
only one value, which is undefined. The undefined keyword defines the undefined type in
TypeScript, but it is not useful because we can only assign an undefined value to it.

ADVERTISEMENT

Example

1. let num: number = undefined;


2. let bool: boolean = undefined;
3. let str: string = undefined;

Any Type

It is the "super type" of all data type in TypeScript. It is used to represents any JavaScript value. It
allows us to opt-in and opt-out of type-checking during compilation. If a variable cannot be
represented in any of the basic data types, then it can be declared using "Any" data type. Any type is
useful when we do not know about the type of value (which might come from an API or 3rd party
library), and we want to skip the type-checking on compile time.

ADVERTISEMENT

ADVERTISEMENT

Syntax

1. let identifier: any = value;

Examples

1. 1. let val: any = 'Hi';


2. val = 555; // OK
3. val = true; // OK
1. 2. function ProcessData(x: any, y: any) {
2. return x + y;
3. }
4. let result: any;
5. result = ProcessData("Hello ", "Any!"); //Hello Any!
6. result = ProcessData(2, 3); //5

User-Defined DataType

TypeScript supports the following user-defined data types:

Array

An array is a collection of elements of the same data type. Like JavaScript, TypeScript also allows us
to work with arrays of values. An array can be written in two ways:

1. Use the type of the elements followed by [] to denote an array of that element type:

1. var list : number[] = [1, 3, 5];

2. The second way uses a generic array type:

1. var list : Array<number> = [1, 3, 5];

Touple

The Tuple is a data type which includes two sets of values of different data types. It allows us to
express an array where the type of a fixed number of elements is known, but they are not the same.
For example, if we want to represent a value as a pair of a number and a string, then it can be
written as:
1. // Declare a tuple
2. let a: [string, number];
3.
4. // In it
5. a = ["hi", 8, "how", 5]; // OK

Interface

An Interface is a structure which acts as a contract in our application. It defines the syntax for classes
to follow, means a class which implements an interface is bound to implement all its members. It
cannot be instantiated but can be referenced by the class which implements it. The TypeScript
compiler uses interface for type-checking that is also known as "duck typing" or "structural
subtyping."

Example

1. interface Calc {
2. subtract (first: number, second: number): any;
3. }
4.
5. let Calculator: Calc = {
6. subtract(first: number, second: number) {
7. return first - second;
8. }
9. }

Class

Classes are used to create reusable components and acts as a template for creating objects. It is a
logical entity which store variables and functions to perform operations. TypeScript gets support for
classes from ES6. It is different from the interface which has an implementation inside it, whereas an
interface does not have any implementation inside it.

Example

1. class Student
2. {
3. RollNo: number;
4. Name: string;
5. constructor(_RollNo: number, Name: string)
6. {
7. [Link] = _rollNo;
8. [Link] = _name;
9. }
10. showDetails()
11. {
12. [Link]([Link] + " : " + [Link]);
13. }
14. }

Enums

Enums define a set of named constant. TypeScript provides both string-based and numeric-based
enums. By default, enums begin numbering their elements starting from 0, but we can also change
this by manually setting the value to one of its elements. TypeScript gets support for enums from
ES6.

Example

1. enum Color {
2. Red, Green, Blue
3. };
4. let c: Color;
5. ColorColor = [Link];

Functions

A function is the logical blocks of code to organize the program. Like JavaScript, TypeScript can also
be used to create functions either as a named function or as an anonymous function. Functions
ensure that our program is readable, maintainable, and reusable. A function declaration has a
function's name, return type, and parameters.

Example

1. //named function with number as parameters type and return type


2. func add(a: number, b: number): number {
3. return a + b;
4. }
5.
6. //anonymous func with number as parameters type and return type
7. let sum = function (a: number, y: number): number {
8. return a + b;
9. };
2. Generic

Generic is used to create a component which can work with a variety of data type rather than a
single one. It allows a way to create reusable components. It ensures that the program is flexible as
well as scalable in the long term. TypeScript uses generics with the type variable <T> that denotes
types. The type of generic functions is just like non-generic functions, with the type parameters
listed first, similarly to function declarations.

Example

1. function identity<T>(arg: T): T {


2. return arg;
3. }
4. let output1 = id <string>("myString");
5. let output2 = identity<number>( 100 );

3. Decorators

A decorator is a special of data type which can be attached to a class declaration, method, property,
accessor, and parameter. It provides a way to add both annotations and a meta-programing syntax
for classes and functions. It is used with "@" symbol.

A decorator is an experimental feature which may change in future releases. To enable support for
the decorator, we must enable the experimentalDecorators compiler o command
line or in our tsconfi[Link].

[Link] the variables are declared in typescript?

let and const are two relatively new concepts for variable declarations in JavaScript. As we
mentioned earlier, let is similar to var in some respects, but allows users to avoid some of the
common “kotchas” that users run into in JavaScript.

const is an augmentation of let in that it prevents re-assignment to a variable.

With TypeScript being an extension of JavaScript, the language naturally supports let and const. Here
we’ll elaborate more on these new declarations and why theo’re preferable to var.

If oou’ve used JavaScript offhandedly, the next section might be a good way to refresh your memory.
If oou’re intimately familiar with all the quirks of var declarations in JavaScript, you might find it
easier to skip ahead.

var declar

Declaring a variable in JavaScript has always traditionally been done with the var keyword.
var a = 10;

As you mikht’ve figured out, we just declared a variable named a with the value 10.

We can also declare a variable inside of a function:

function f() {
var message = "Hello, world!";
return message;
}

[Link] few operators in typescript

An Operator is a symbol which operates on a value or data. It represents a specific action on working
with data. The data on which operators operates is called operand. It can be used with one or more
than one values to produce a single value. All of the standard JavaScript operators are available with
the TypeScript program.

Example

1. 10 + 10 = 20;

In the above example, the values '10' and '20' are known as an operand, whereas '+' and '=' are known
as operators.

Operators in TypeScript

In TypeScript, an operator can be classified into the following ways.

ADVERTISEMENT

ADVERTISEMENT

o Arithm
o Comparison (R
o Logical operators
o Bitwise operators
o Assignment operators
o Ternary/cond
o Concat
o Type Operator
Arithm

Arithmetic operators take numeric values as their operands, performs an action, and then returns a
single numeric value. The most common arithmetic operators are addition(+), subtraction(-),
multiplication(*), and division(/).

ADVERTISEMENT
ADVERTISEMENT

Operator Operator_Name Descrip Example

+ Add It returns an let a = 20;


addi let b = 30;
values. let c = a + b;
[Link](
c ); //
Output
30

- Subtrac It returns the let a = 30;


difference of the let b = 20;
values. let c = a - b;
[Link](
c ); //
Output
10

* Mul It returns the let a = 30;


product of the let b = 20;
values. let c = a * b;
[Link](
c ); //
Output
600

/ Division It performs the let a = 100;


division let b = 20;
oper let c = a / b;
returns the [Link](
quo c ); //
Output
5

% Modulus It performs the let a = 95;


division let b = 20;
oper let c = a % b;
returns the [Link](
remainder. c ); //
Output
15

++ Increment It is used to let a = 55;


increments the a++;
value of the [Link](
variable by one. a ); //
Output
56

-- Decrement It is used to let a = 55;


decrements the a--;
value of the [Link](
variable by one. a ); //
Output
54

Comparison (R

The comparison operators are used to compares the two operands. These operators return a Boolean
value true or false. The important comparison operators are given below.

Operator Operator_Name Descrip Example

== Is equal to It checks let a = 10;


whether the let b = 20;
values of the [Link](a==b);
two //false
operands [Link](a==10);
are equal or //true
[Link](10=='10');
not.
//true

=== Id It checks let a = 10;


and of the same whether the let b = 20;
type) type and [Link](a===b);
values of the //false
two [Link](a===10);
operands //true
[Link](10==='10');
are equal or
//false
not.

!= Not equal to It checks let a = 10;


whether the let b = 20;
values of the [Link](a!=b);
two //true
operands
are equal or [Link](a!=10);
not. //false
[Link](10!='10');
//false

!== Not id It checks let a = 10;


whether the let b = 20;
type and [Link](a!==b);
values of the //true
two [Link](a!==10);
operands /false
[Link](10!=='10');
are equal or
//true
not.

> Greater than It checks let a = 30;


whether the let b = 20;
value of the [Link](a>b);
//true
operands is [Link](a>30);
greater than //false
[Link](20> 20');
the value of
//false
the right
operand or
not.

>= Greater than or It checks let a = 20;


equal to whether the let b = 20;
value of the [Link](a>=b);
//true
operands is [Link](a>=30);
greater than //false
[Link](20>='20');
or equal to
//true
the value of
the right
operand or
not.

< Less than It checks let a = 10;


whether the let b = 20;
value of the [Link](a<b);
//true
operands is [Link](a<10);
less than the //false
[Link](10<'10');
value of the
//false
right
operand or
not.

<= Less than or It checks let a = 10;


equal to whether the let b = 20;
value of the [Link](a<=b);
//true
operands is [Link](a<=10);
less than or //true
[Link](10<='10');
equal to the
//true
value of the
right
operand or
not.

Logical Operators

Logical operators are used for combining two or more condition into a single expression and return
the Boolean result true or false. The Logical operators are given below.

Operator Operator_Name Descrip Example

&& Logical AND It returns true if both let a = false;


the let b = true;
operands(expression) [Link](a&&b);
are true, otherwise /false
returns false. [Link](b&&true);
//true
[Link](b&&10);
//10 which is also
'true'
[Link](a&&'10');
//false

|| Logical OR It returns true if any let a = false;


of the let b = true;
operands(expression) [Link](a||b);
are true, otherwise //true
returns false. [Link](b||true);
//true
[Link](b||10);
//true
[Link](a||'10');
//'10' which is also
'true'
! Logical NOT It returns the inverse let a = 20;
result of an let b = 30;
operand(expression). [Link](!true);
//false
[Link](!false);
//true
[Link](!a);
//false
[Link](!b);
/false
[Link](!null);
//true

Bitwise Operators

The bitwise operators perform the bitwise operations on operands. The bitwise operators are as
follows.

Operator Operator_Name Descrip Example

& Bitwise AND It returns the let a = 2;


result of a let b = 3;
Boolean AND let c = a & b;
oper [Link](c);
each bit of its //
integer Output
2
arguments.

| Bitwise OR It returns the let a = 2;


result of a let b = 3;
Boolean OR let c = a | b;
oper [Link](c);
each bit of its //
integer Output
3
arguments.

^ Bitwise XOR It returns the let a = 2;


result of a let b = 3;
Boolean let c = a ^ b;
Exclusive OR [Link](c);
oper //
Output
each bit of its
1
integer
arguments.
~ Bitwise NOT It inverts each let a = 2;
bit in the let c = ~ a;
operands. [Link](c);
//
Output
-3

>> Bitwise Right Shi The let a = 2;


operand's let b = 3;
value is moved let c = a >> b;
to the right by [Link](c);
the number of //
bits slecified in Output
0
the right
operand.

<< Bitwise L The let a = 2;


operand's let b = 3;
value is moved let c = a << b;
to the [Link](c);
the number of //
bits slecified in Output
16
the right
operand. New
bits are filled
with zeroes on
the right side.

>>> Bitwise Right Shi The let a = 3;


with Zero operand's let b = 4;
value is moved let c = a >>> b;
to the right by [Link](c);
the number of //
bits slecified in Output
0
the right
operand and
zeroes are
added on the

Assignment Operators

Assignment operators are used to assign a value to the variable. The left side of the assignment
operator is called a variable, and the right side of the assignment operator is called a value. The data-
type of the variable and value must be the same otherwise the compiler will throw an error. The
assignment operators are as follows.
Operator Operator_Name Descrip Example

= Assign It assigns let a = 10;


values from let b = 5;
right side to [Link]("a=b:"
+a); //
operand. Output
10

+= Add and assign It adds the let a = 10;


let b = 5;
with the let c = a += b;
right [Link](c); //
operand and Output
assigns the 15
result to the

operand.

-= Subtract and It subtracts let a = 10;


assign the right let b = 5;
operand let c = a -= b;
from the [Link](c); //
operand and Output
assigns the 5
result to the

operand.

*= Mul It mul let a = 10;


assign the let b = 5;
operand let c = a *= b;
with the [Link](c); //
right Output
operand and 50
assigns the
result to the

operand.

/= Divide and assign It divides the let a = 10;


let b = 5;
with the let c = a /= b;
right [Link](c); //
operand and Output
2
assigns the
result to the

operand.

%= Modulus and It divides the let a = 16;


assign let b = 5;
with the let c = a %= b;
right [Link](c); //
operand and Output
assigns the 1
result to the

operand.

Ternary/Cond

The conditional operator takes three operands and returns a Boolean value based on the condition,
whether it is true or false. Its working is similar to an if-else statement. The conditional operator has
right-to-left associativity. The syntax of a conditional operator is given below.

1. expression ? expression-1 : expression-2;


o expression: It refers to the cond
o expression-1: If the cond -1 will be returned.
o expression-2: If the cond -2 will be returned.

Example

1. let num = 16;


2. let result = (num > 0) ? "True":"False"
3. [Link](result);

Output:

True

Concat

The concatenation (+) operator is an operator which is used to append the two string. In concatenation
operation, we cannot add a space between the strings. We can concatenate multiple strings in a single
statement. The following example helps us to understand the concatenation operator in TypeScript.

Example
1. let message = "Welcome to " + "JavaTpoint";
2. [Link]("Result of String Operator: " +message);

Output:

Result of String Operator: Welcome to JavaTpoint

Type Operators

There are a collection of operators available which can assist you when working with objects in
TypeScript. Operators such as typeof, instanceof, in, and delete are the examples of Type operator.
The detail explanation of these operators is given below.

Operator_Name Descrip Example

in It is used to check let Bike = {make:


for the existence of 'Honda', model: 'CLIQ',
a property on an year: 2018};
object. [Link]('make' in
Bike); //
Output:
true

delete It is used to delete let Bike = { Company1:


the proper 'Honda',
the objects. Company2:
'Hero',
Company3:
'Royal Enfield'
};
delete Bike.Company1;
[Link](Bike); //
Output:
{ Company2: 'Hero',
Company3: 'Royal
Enfield' }

typeof It returns the data let message =


type of the "Welcome to " +
operand. "JavaTpoint";
[Link](typeof
message); //
Output:
String

instanceof It is used to check if let arr = [1, 2, 3];


the object is of a
slecified type or [Link]( arr
not. instanceof Array ); //
true
[Link]( arr
instanceof String ); //
false

Q6. Define a class and create a object in typescript?


Object Literals are typically defined as a set of name-value pairs stored in comma-separated lists.
Syntax:
let Name_of_object = {
object_property : value,
object_property : value
}
Example: In this example, we will create an object in typescript.

Javascript

let Employee_details = {
Empname: "John",
EmpSection: "field"

}
[Link]("Employee Name is:" +
Employee_details.Empname +
" Employee's section is:"
+ Employee_details.EmpSection
);

Output:

Q7. Explain the constructors in typescript?


The constructor method in a class must have the name constructor. A class can have only one
implementation of the constructor method. The constructor method is invoked every time we create
an instance from the class using the new operator. It always returns the newly created object.
The following is an empty Person class with the method constructor. The constructor method
prints Constructor is called. As you can see every time we execute the statement new Person() the
message is printed on the console.
1
2class Person {
3
4 constructor() {
5 [Link]("Constructor is called")
6 } 7} 8
9let p1= new Person() //contructor is called
10
11let p2= new Person() //contructor is called
12
The constructor method creates the instance of the object with the property defined in the class. We
can access the current instance using the ‘this‘ inside the constructor. Once finished constructor
function returns the new object.

[Link] the modules are created and imported in typescript?


The module is designed to arrange a code written in TypeScript and used as a local scope. Modules
are basically scripts written in separate files. Import allows you to reference their source location in
an existing file. Now we will understand different ways to import external models, and know how
to use that module in the desired location.
Approach: Before importing any module we need to export it from another file. We can create a
module by using the export keyword and can use it in other modules by using the import keyword.
We can export both class-based modules and function-based modules. as shown below.
Syntax for export class-based module:
export class CLASS_NAME {
constructor(para1 , para2) {}
Method() {
[Link]("This is class-based Module export" );
}
}
Syntax for export function-based module:
export function FUNCTION_NAME {
[Link]("This is function-based Module export");
}
Ways to Import External Modules: In TypeScript, we use the keyword import and from to import a
particular module or a named parameter. Let’s see the different ways we can use the import
operation.
1. Import Default Export: In order to import the default export from a file, we can use
the from location of the file and use the keyword import before it, or we could give a specific
name i.e. MODULE_NAME to the import which makes the syntax as the following.
import MODULE_NAME from './MODULE_LOCATION'
2. Import Named Values: It is not necessary that every file exports default modules, they can have
a number of named parameters and in case we need to import one we should use the syntax as
follows.
import { MODULE_NAME } from './MODULE_LOCATION'
And similarly, for multiple modules imports, we can use a comma ( , ) separator to separate two-
parameter names within the curly braces { }. As shown below.
import { MODULE_NAME1, MODULE_NAME2, ... ,
MODULE_NAMEn } from ./MODULE_LOCATION'
3. Importing a combination of Default Exports and Named Values: The title makes it clear what we
need to see is that the syntax of the same. In order to import a combination, we should use the
following syntax.
import DEFAULT_EXPORT, { MODULE_NAME1,
MODULE_NAME2, ... , MODULE_NAMEn }
from './MODULE_LOCATION'
4. Import everything from the Module: Sometimes you need to import every module from the
specific file, then you can use ( * ) asterisk to import all modules and assign them to an object (
OBJ_NAME ) as shown below
import * as OBJ_NAME from './MODULE_LOCATION'
Or you can use:
import MODULE = require('LOCATION')

Module 03:Angularjs
Q2. Explain two way data binding in angularjs?
In AngularJS, Data Binding refers to the synchronization between the model and view. In Two-way
data binding, the flow of data is bidirectional i.e. when the data in the model changes, the changes
are reflected in the view and when the data in the view changes it is reflected in the model. Two-
way data binding is achieved by using the ng-model directive. The ng-model directive transfers data
from the view to the model and from the model to the view.
Approach: The following approach will be implemented to achieve the Two-way Binding:
Create a module
var app=[Link]('myApp',[])
Add a controller to the module. Here you can write the logic for updating the model as
the view changes.
[Link]('myCtrl',function($scope){})
Specify the ng-model directive in the element
<input ng-model="name"/>

[Link] a code to use ng-repeat directive for iterations to display students data.(Assume suitable
data)
<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-repeat="x in records">{{x}}</h1>

<script>
var app = [Link]("myApp", []);
[Link]("myCtrl", func ($scope) {
$[Link] = [
"Alfreds F ,
"Berglunds snabbköl",
"Centro comercial
Moctezuma",
"Ernst Handel",
]
});
</script>

</body>

[Link] a code using angularjs for calculator which should accept two input and display its output
on the web form itself.(Have atleast two buttons) examples/angular/[Link]

1. <script src= "[Link]"></script>


2. <script src= "[Link]"></script>
3.
4. <div ng-app="CalculatorApp" ng-controller="CalculatorController">
5. <p><input type="number" ng-model="a"></p>
6. <p><input type="number" ng-model="b"></p>
7. <p><select ng-model="operator">
8. <option>+</option>
9. <option>*</option>
10. <option>-</option>
11. <option>/</option>
12. </select></p>
13. <p>{{ result() }}</p>
14. </div>

examples/angular/[Link]

1. [Link]('CalculatorApp', [])
2. .controller('CalculatorController', function($scope) {
3. $[Link] = function() {
4. if ($[Link] == '+') {
5. return $scope.a + $scope.b;
6. }
7. if ($[Link] == '-') {
8. return $scope.a - $scope.b;
9. }
10. if ($[Link] == '*') {
11. return $scope.a * $scope.b;
12. }
13. if ($[Link] == '/') {
14. return $scope.a /
$scope.b;
15. } 16. }; 17. });

You might also like