Podcast
Questions and Answers
What are the two ways to add JavaScript to Web pages?
What are the two ways to add JavaScript to Web pages?
What is the purpose of the type
attribute within the <script>
tag?
What is the purpose of the type
attribute within the <script>
tag?
text/javascript
What is the common method to write text to HTML output?
What is the common method to write text to HTML output?
document.write()
The document.write()
method should be used for production code.
The document.write()
method should be used for production code.
Signup and view all the answers
What is the type of JavaScript that is interpreted on the fly?
What is the type of JavaScript that is interpreted on the fly?
Signup and view all the answers
JavaScript can be incorporated from an external file?
JavaScript can be incorporated from an external file?
Signup and view all the answers
What does the window.alert()
function do?
What does the window.alert()
function do?
Signup and view all the answers
Is the console.log()
function used to display data in debug mode in the browser?
Is the console.log()
function used to display data in debug mode in the browser?
Signup and view all the answers
Which of these keywords is used to declare a variable?
Which of these keywords is used to declare a variable?
Signup and view all the answers
What does the let
keyword represent?
What does the let
keyword represent?
Signup and view all the answers
Javascript is case-sensitive?
Javascript is case-sensitive?
Signup and view all the answers
What does each line end with in JavaScript code?
What does each line end with in JavaScript code?
Signup and view all the answers
Is it possible to have multiple statements on a single line in Javascript?
Is it possible to have multiple statements on a single line in Javascript?
Signup and view all the answers
What is the purpose of a block in JavaScript?
What is the purpose of a block in JavaScript?
Signup and view all the answers
Match the following JavaScript keywords/concepts with their descriptions:
Match the following JavaScript keywords/concepts with their descriptions:
Signup and view all the answers
Variables declared using let
cannot be redeclared.
Variables declared using let
cannot be redeclared.
Signup and view all the answers
Variables declared using let
can be used outside of the block they were declared in.
Variables declared using let
can be used outside of the block they were declared in.
Signup and view all the answers
What is the purpose of the const
keyword in Javascript?
What is the purpose of the const
keyword in Javascript?
Signup and view all the answers
Match the JavaScript Operators with their description:
Match the JavaScript Operators with their description:
Signup and view all the answers
What is the purpose of the =
operator?
What is the purpose of the =
operator?
Signup and view all the answers
Match the JavaScript assignment operators with their equivalent expressions:
Match the JavaScript assignment operators with their equivalent expressions:
Signup and view all the answers
What is the difference between the ==
operator and the ===
operator?
What is the difference between the ==
operator and the ===
operator?
Signup and view all the answers
JavaScript can only work with numbers?
JavaScript can only work with numbers?
Signup and view all the answers
Can you redeclare a variable declared using var
?
Can you redeclare a variable declared using var
?
Signup and view all the answers
What is the output of the following JavaScript code: let x = "5" + 2 + 3; console.log(x);
What is the output of the following JavaScript code: let x = "5" + 2 + 3; console.log(x);
Signup and view all the answers
What is the output of the following JavaScript code: let x = 2 + 3 + "5"; console.log(x);
What is the output of the following JavaScript code: let x = 2 + 3 + "5"; console.log(x);
Signup and view all the answers
The output of a Javascript script will always appear in the HTML output?
The output of a Javascript script will always appear in the HTML output?
Signup and view all the answers
Signup and view all the answers
Study Notes
Introduction to JavaScript - Part I
- JavaScript is a client-side scripting language.
- It was developed in just 10 days in May 1995 by Netscape.
- It was initially called LiveWire and then LiveScript.
- It runs within the client software (the browser).
- JavaScript is interpreted on the fly by the client, meaning each line is processed as soon as it's loaded into the browser.
- Server-side languages, like PHP and Python, run on the web server.
- JavaScript is significantly easier to learn compared to other programming languages.
- It's a convenient way to create interactive web pages.
Topics
- What is JavaScript?
- Why JavaScript?
- Including JavaScript in HTML (two methods):
- Using the
<script>...</script>
tag directly within the HTML. - Using an external JavaScript file (with
<script src="filename.js"></script>
).
- Using the
- Hello World Example Script: Shows basic JavaScript code to display text on a web page.
- JavaScript Comments (two types):
- Single-line comments use
//
. - Multi-line comments use
/* ... */
.
- Single-line comments use
Including JavaScript in HTML
- Scripts can be placed in the
<body>
, or in the<head>
section of an HTML page, or in both sections.
Hello World Example Script
- The code
document.write("<h1>Hello, world!</h1>");
displays "Hello, world!" in an h1 heading on the web page.
JavaScript Comments
- Single-line comments start with
//
. - Multi-line comments start with
/*
and end with*/
.
JavaScript Functions
- JavaScript functions perform specific tasks.
- A function is a block of code that is designed to perform a particular task.
- To create a function, use the
function
keyword. - Functions can be called by other parts of a program.
- A function can have one or many parameters.
- The
document.getElementById("p1").innerHTML ="New Text !";
command displays the text "New Text" in a HTML element with the ID "p1".
Outputs in JavaScript
-
document.write()
: Writes to the HTML page content, but be warned this can overwrite existing content. -
window.alert()
: Displays an alert box. -
console.log()
: Displays output in the browser's developer console (useful for debugging).
innerHTML Property
- The
innerHTML
property is used to update the content of an HTML element. - This is done using JavaScript, without affecting the structure of the page.
Using document.write()
- The
document.write()
method writes a string of text to a web page. - It should only be used when needed for testing.
- Using
document.write()
after the content is loaded, will delete all existing content.
window.alert()
- The
window.alert()
method displays an alert dialog box with the specified text on the screen.
console.log()
- The
console.log()
method displays the specified data in the browser's developer tools' console.
window.print()
- The
window.print()
method prints the current web page.
JavaScript Statements
- A JavaScript program consists of a series of statements.
- Statements are commands or instructions that tell the interpreter what to do.
- A statement ends in a semicolon.
JavaScript Syntax
- JavaScript syntax defines the structure and rules for JavaScript code.
- A statement often includes variables.
- Variables are temporary named storage locations to hold data, variables are defined using keywords like
let
orvar
.
Defining JS Variables
- Javascript variables are declared with
var
,let
, orconst
. - The
var
keyword was used historically. -
let
andconst
are newer, introduce block scope, and can not be redeclared. - JavaScript identifiers (variable names) are case-sensitive.
- Several data types exist (strings, numbers, etc.) in JavaScript.
Let - Block Scope
- Variables declared with
let
have block scope - they are only accessible within the block of code they are declared in.
JavaScript Operators
- Arithmetic Operators:
+
,-
,*
,/
,%
,**
- Assignment Operators:
=
,+=
,-=
,*=
,/=
,%=
- Other Operators:
++
,--
(increment, decrement)
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the basics of JavaScript, initially developed by Netscape in 1995. Learn about its purpose, how to include it in HTML, and the fundamental concepts essential for creating dynamic web pages. Ideal for beginners looking to understand client-side scripting.