LEARN JAVASCRIPT QUICKLY AND JAVASCRIPT CODING EXERCISES Coding For Beginners (TAM, JJ [TAM, JJ]) (Z-Library)
JavaScript
No Description
273
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
LEARN JAVASCRIPT QUICKLY AND JAVASCRIPT CODING EXERCISES CODING FOR BEGINNERS WITH HANDS ON PROJECTS BY J J TAM
Page
3
Introduction to Javascript Javascript: Hello world program Javascript: Variables Javascript: Statements Javascript: comments JavaScript: Types Javascript: operators Javascript: Arithmetic Operators Javascript: Increment/decrement: ++, -- operators Javascript: Bitwise operators JavaScript: Logical operators JavaScript: Assignment operators JavaScript: Compound Assignment operator Javascript: Ternary operator JavaScript: Working with boolean values JavaScript: Decision Making: if, if-then Javascript: if-else-if-else ladder JavaScript: Decision making using switch statement JavaScript: loops
Page
4
JavaScript: do-while loop JavaScript: for loop JavaScript: break statement JavaScript: continue statement JavaScript: break in label form JavaScript: for in loop JavaScript: for-of loop JavaScript: get the type of variable JavaScript: Working with strings JavaScript: Nested functions JavaScript: Array JavaScript: Introduction to Classes JavaScript: Define class using class expressions JAVASCRIPT CODING EXERCISES Display the current day and time Print the contents Display the current date Find the area of a triangle Check whether a given year is a leap year
Page
5
Calculate multiplication and division Convert temperatures Find the largest Reverse a given string Replace every character Capitalize The First Letter Convert number to hours and minutes Count vowels in a given string Create a new string Concatenate two strings Move last three character Compute the sum Add two digits Check whether a given year is a leap Check given positive number Check a string starts with 'Java' Check two given integer values Find a value which is nearest to 100
Page
6
Introduction to Javascript Javascript is a scripting language, used to validate html form data, before submitting to the server. Now a days javaScript is also used for server side development (Read node.js) What can I do with Javascript? a. You can perform client side validation. b. You can give dynamic behavior to static HTML pages. c. Show animations on web page d. You can update partial portion of page using AJAX. e. Develop Server side applications using frameworks like node.js Javascript is interpreted language Javascript is interpreted language, write once and attach it to HTML page. No further compilation is required. Is there any relation between JavaScript and Java? Absolutely there is no relation between JavaScript and Java. What is ECMAScript? ECMAScript is a standard, JavaScript is the language that implement ECMAScript standard. Is JavaScript supports Unicode? JavaScript programs are written in Unicode. ECMAScript 5 standard supports Unicode 3. Is JavaScript case-sensitive? Yes JavaScript is a case sensitive language.
Page
7
Is it compulsory to end statement using ;? Many languages like Java, C, C++ use ; as statement terminator. Usage of ; is optional in JavaScript, but I always prefer to use ; to maintain consistency. Is JavaScript support automatic garbage collection? Yes, JavaScript support automatic garbage collection, whenever JavaScript interpreter finds an unreachable object (or) variable, it frees the memory allocated for that variable (or) object. Is JavaScript an object oriented language? Yes, JavaScript is an object-oriented language, but the kind of inheritance it provides is different from the inheritance provided by languages like Java and C++. JavaScript supports Prototype inheritance.
Page
8
Javascript: Hello world program helloWorld.html <!DOCTYPE html> <html> <head> <title>Hello world</title> </head> <body> <script type="text/javascript"> document.write("Hello World"); </script> </body> </html> document.write("Hello World"); Above statement gives instruction to the browser to write "Hello World". Java Script is embedded between <script></script> tags.
Page
9
Javascript: Variables Variable holds a value. Following are some of the examples of variables. var name = "Krishna" var id=123 Above statements define two variables name, id. ‘var’ keyword is used to define variables. Naming constraints a. Variable name must begin with any alphabet, _ (or) $. b. Variable name can contain any character. c. Spaces are not allowed in between variable names. d. Don’t use Javascript keywords as variable names. e. Variable names are case sensitive. Name, NAme, name are 3 different variables. variables.html <!DOCTYPE html> <html> <head> <title>Variables</title> </head> <body> <script type="text/javascript"> var name = "Krishna" ;
Page
10
var id=123; document.write("name = " + name + "<br />"); document.write("id = " + id); </script> </body> </html> Note Java script is case sensitive, so the names banana, Banana, BaNaNa are three different variables.
Page
11
Javascript: Statements Statement is an executable statement, statements in Javascript are terminated using ‘;’. statements.html <!DOCTYPE html> <html> <head> <title>Variables</title> </head> <body> <script type="text/javascript"> document.write("Hello World" + "<br />"); document.write("Hello PTR"); </script> </body> </html> In the above example, below are the java script statements. document.write("Hello World" + "<br />"); document.write("Hello PTR");
Page
12
Javascript: comments Comments are used to document the source code. Comments in javaScript, makes the program more readable. Comments are ignored by JavaScript. Suppose you written thousand lines of program, with out proper documentation, after some time, for the owner of the application also, it is very difficult to figure out what was written. Comments solve this problem: By using comments, you can document your code at the time of writing program. Comments won't affect your program execution. Comments simply document your code. Javascript support 2 kinds of comments. a. Single line comments b. Multi line comments Single line comment : Single line comments starts with // // It is a single line comment Multi Line comment Multi line comments are encoded in /* */ /* I am a mulltiline comment */ sample.html <!DOCTYPE html>
Page
13
<html> <head> <title>Variables</title> </head> <body> <script type="text/javascript"> /* Java script is weakly typed language Author: Hari krishna */ var a = 10; document.write("Value of a is " + a + "<br />"); a = "Hello World"; // Assigning string document.write("Value of a is " + a + "<br />"); a = true; // Assigning boolean document.write("Value of a is " + a + "<br />"); a = 10.09; // Assigning number document.write("Value of a is " + a + "<br />"); </script> </body> </html>
Page
14
JavaScript: Types Types are used to represent the type of data. Primarily, there are two categories of types. a. Primitive types b. Reference types Primitive Types Numbers, strings and Boolean values considered as primitive types. In addition to these, special values null, undefined are also considered as primitive types. Reference Types Objects and arrays are considered as reference types. An object is a collection of name and value pairs. Array is a collection of elements. One more thing to note is that JavaScript treats functions also objects. types.html <!DOCTYPE html> <html> <head> <title>Data Types</title> </head> <body> <script >
Page
15
var a = 10; var b = 10.01; var c = true; var d = "Hello World"; var e = { name : "Hari krishna", city : "Bangalore" }; var f = [2, 3, 5, 7]; document.write("a = " + a + " Type of a = " + (typeof a) + "<br />"); document.write("b = " + b + " Type of b = " + (typeof b) + "<br />"); document.write("c = " + c + " Type of c = " + (typeof c) + "<br />"); document.write("d = " + d + " Type of d = " + (typeof d) + "<br />"); document.write("e = " + e + " Type of e = " + (typeof e) + "<br />"); document.write("f = " + f + " Type of f = " + (typeof f) + "<br />"); </script> </body> </html> Open above page in browser, you can able to see following
Page
16
messages in the html page. a = 10 Type of a = number b = 10.01 Type of b = number c = true Type of c = boolean d = Hello World Type of d = string e = [object Object] Type of e = object f = 2,3,5,7 Type of f = object As you see the output, JavaScript treats both integer and float values as type number and arrays, objects are treated as type object.
Page
17
Javascript: operators An operator is a symbol which perform an operation An operator is said to be unary, if it performs operation on single operand. An operator is said to be binary, if it performs operation on two operands An Operator is said to be ternary if it perform operation on three operands. Javascript provides following operators. a . Arithmetic operators b . Increment/decrement:++, -- c . Bitwise operators d . Logical operators e . Assignment operators f . String concatenation g . Comparison operators h. Other operators like === (Strict comparison), ternary (?:)
Page
18
Javascript: Arithmetic Operators Following table summarizes Arithmetic operators supported by Javascript. Operator Description + Additon (also used for String concatenation) - Subtraction / Division * Multiplication % Gives Remainder arithmetic.html <!DOCTYPE html> <html> <head> <title> Arithmetic Operators </title> <style> p { font-size : 2em ; color : seagreen ; } </style> </head> <body> <p> <script type= "text/javascript" > var a = 23 ; var b = 3 ;
Page
19
document .write( "a = " + a + "<br />" ); document .write( "b = " + b + "<br />" ); document .write( "a+b = " + (a + b) + "<br />" ); document .write( "a-b = " + (a - b) + "<br />" ); document .write( "a*b = " + (a * b) + "<br />" ); document .write( "a/b = " + (a / b) + "<br />" ); document .write( "a%b = " + (a % b) + "<br />" ); </script> </p> </body> </html> Note Unlike languages like Java, integer division in JavaScript returns float value.
Page
20
Javascript: Increment/decrement: ++, -- operators Increment & decrement operators ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 Pre increment Syntax: ++variable pre increment operator increments the variable value by 1 immediately. Post increment Syntax: variable++ post increment operator increments the variable value by 1 after executing the current statement. Pre Decrement Syntax: --variable pre decrement operator decrements the variable value by 1 immediately. Post Decrement Syntax: variable--
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# Learn JavaScript Quickly and JavaScript Coding Exercises — Reading Guide
## 【One-Line Pitch】
A beginner-friendly, example-driven JavaScript primer that pairs language fundamentals with hands-on coding exercises, ideal for absolute newcomers who learn best by typing code and seeing immediate browser output.
---
## 【Book Arc】
- **Opening (~0%–14%)**: Introduces JavaScript basics—Hello World, variables, statements, comments, and data types—with an emphasis on JavaScript's weakly typed nature and how to embed scripts in HTML pages.
- **Early (~14%–29%)**: Covers the full operator toolkit: arithmetic, increment/decrement, bitwise, logical, assignment, compound assignment, and ternary operators, each illustrated with runnable HTML examples.
- **Middle (~29%–57%)**: Moves into control flow—boolean truthiness rules, if/else-if/else ladders, switch statements, and all three loop constructs (while, do-while, for)—plus break statements in both plain and labeled forms.
- **Middle (~57%–64%)**: Explores data structures and type introspection, including the typeof operator, string handling, array indexing limits, and for-in loops for traversing object properties and arrays.
- **Late (~64%–71%)**: Introduces object-oriented concepts—constructor functions, the `this` keyword, class syntax (both named and anonymous class expressions)—and demonstrates how to build and print employee objects.
- **Ending (~71%–100%)**: Transitions into the coding exercises section, presenting practical challenges like displaying the current date/time, printing window contents, and other beginner drills that reinforce earlier concepts.
---
## 【Key Takeaways】
- **JavaScript is weakly typed** (Early): A single variable can hold numbers, strings, booleans, objects, or arrays at different times—the `typeof` operator reveals the current type. This flexibility is powerful but demands awareness of what values you're working with.
- **Semicolons are optional but recommended** (Early): Unlike Java or C++, JavaScript doesn't require statement terminators, yet consistent use of `;` prevents ambiguity and maintains code clarity across browsers and parsers.
- **Truthiness follows specific rules** (Middle): Only `undefined`, `null`, `+0`, `-0`, `NaN`, and empty strings evaluate to `false`—everything else is `true`. Understanding this list prevents subtle bugs in conditionals.
- **Short-circuit evaluation matters** (Early): Logical OR stops evaluating once an operand is `true`, which is why it's called a short-circuit operator—this behavior can be exploited for concise conditional assignments.
- **Bitwise operators work on 32-bit representations** (Early): JavaScript bitwise operations like `~`, `<<`, `>>`, and `>>>` operate on 32-bit signed integers, with two's complement used for negative numbers—useful for low-level manipulation but rarely needed in everyday coding.
- **Arrays are objects with 32-bit indexes** (Middle): Arrays can hold mixed types and have a maximum index of 4,294,967,294 (2^32 − 2). The `for-in` loop traverses enumerable properties, including array indices.
- **JavaScript supports prototype-based OOP** (Late): Classes and constructor functions create objects with properties set via `this`, and embedded functions can access variables from parent scopes—a different inheritance model than Java or C++.
- **Practice reinforces theory** (Ending): The exercise section applies syntax to real tasks like date formatting and window manipulation, showing how small programs combine variables, conditionals, and built-in objects.
---
## 【Reading Tips】
- **Skim the HTML boilerplate**: Every example wraps JavaScript in full HTML documents with `<script>` tags. Focus on the JavaScript logic inside, not the repetitive page structure.
- **Type and run each example**: The book's value comes from execution. Open the HTML files in a browser and observe outputs—especially for operators and loops where results may surprise beginners.
- **Deep-read the bitwise and truthiness sections**: These are the trickiest parts for newcomers. Work through the binary examples on paper, and memorize the false-value list before moving on.
- **Use the exercise section as a test**: After finishing the fundamentals, attempt each coding exercise before checking the provided solution—this transforms passive reading into active learning.
- **Don't expect modern JavaScript features**: The book uses `var` throughout and reflects older teaching styles. If you're learning for current web development, supplement with resources covering `let`, `const`, arrow functions, and ES6+ syntax.
---
## 【Coverage Limits】
This guide synthesizes the first ~71% of the book (language fundamentals) plus the opening of the exercise section. The full exercise solutions and any later advanced topics are not covered in the available excerpts.
---
##
Passage locations
Page 9
riable holds a value. Following are some of the examples of variables. var name = "Krishna" var id=123 Above statements define two variables name, id. ‘var’...
View in text
Excerpt 2
ment .write( "++a = " + ( ++ a) + "<br />" ); document .write( "a-- = " + (a -- ) + "<br />" ); document .write( "--a = " + ( -- a) + "<br />" ); </script> <...
View in text
Excerpt 3
the condition true } if.html <!DOCTYPE html> <html> <head> <title> if statement </title> </head> <body> <script type= "text/javascript" > var a = prompt( "En...
View in text
Excerpt 4
from 0 to " + number + " are </h2>" ); var i = 0 ; while (i <= number) { if (number >= 100 ) { document .write( "Input should be < 100" ); break ; } document...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay