JavaScript
The current, editable version of this book is available in Wikibooks, the open-
content textbooks collection, at
https://en.wikibooks.org/wiki/JavaScript
Permission is granted to copy, distribute, and/or modify
this document under the terms of the Creative Commons
Attribution-ShareAlike 3.0 License.
,Contents
Introduction
Dynamic data types
Functional programming
Object-orientated programming
C-like syntax
Relation to Java
JS engines
References
Relation to other languages
Behavior of Variables
Scope of Variables
Classes
First program
Exercises
JavaScript within HTML
Internal vs. external JavaScript
External JavaSscript
The src attribute
The type attribute
The async and defer attributes
Location of <script> elements
The <noscript> element
JavaScript in XHTML files
Reference
Handling Events
Second Example
Development Tools
Development Stage
Locally installed Tools
Online
Validation
Optimization, Obfuscating
Self Test
Introduction
Syntax and Semantic
Type Conversion
Loops
Helpful hints
Predefined functions
alert()
log()
, print()
prompt()
write()
Coding style
Faulty visualization in some code examples
Lexical structure
Summary
Case Sensitivity
Whitespaces
Comments
Semicolons
Literals
Identifiers
Exercises
Notes
References
Automatic semicolon insertion
See also
Reserved words
References
Variables
Purpose
Declaration and initialization
Keyword let
Keyword const
Keyword var
Omitting the declaration
Data types
Scope
Block scope
Function scope
Module scope
Global scope
Exercises
See also
References
Data types
Introduction
Categories of data types
References
Primitive data types
String
Properties and methods for strings
length
, concat(text)
indexOf(searchText)
lastIndexOf(searchText)
replace(text, newtext)
slice(start [, end])
substr(start [, number of characters])
substring(start [, end])
toLowerCase()
toUpperCase()
Number
Properties and methods for numbers
Properties
Math.ceil(number)
Math.floor(number)
Math.round(number)
Math.max(number_1, number_2)
Math.min(number_1, number_2)
Math.random()
Number.parseInt(string)
Number.parseFloat(string)
BigInt
Boolean
Undefined
Null
Symbol
See also
Exercises
References
Objects
Create an object
Read a property
Add or modify a property
Delete a property
Merge objects
Functions/methods as part of an object
Exercises
Arrays
Create an array
Access an array element
Varying data types
Nested arrays
Properties and methods
length
concat
join and split