Codigos de Java Ingles
Codigos de Java Ingles
To create separate file, use extension .js and include the file on the page as –
<script src="myjsfile.js"></script>
Arrays
Arrays group similar kinds of data together. Eg, var subjectlist = [“math”, “science”,
“history”, “computer”]; Arrays can perform the following functions:
Functions Description
Operators
• Addition (+)
• Subtraction (-)
• Multiply (*)
• Divide (/)
Basic • Remainder (%)
• Increment (++)
• Decrement (--)
• Execute brackets first (…)
• And (&&)
• Or (||)
Logical
• Not (|)
• Equal to (==)
• Equal value and type (===)
• Not equal (!=)
• Not equal value or type (!==)
• Greater than (>)
Comparison
• Less than (<)
• Greater than or equal to (>=)
• Less than or equal to (<=)
• Ternary operator (?)
• AND (&)
• OR (|)
• NOT (~)
• XOR (^)
Bitwise
• Left shift (<<)
• Right shift (>>)
• Zero fill right shift (>>>)
Function
A group of tasks can be performed in a single function. Eg,
add(a, b){// code}
console.log() Mainly used for debugging, write output on the browser console
confirm() Open dialog with yes/no and return true/false based on user click
Global Functions
var a = parseInt(“2003 m
parseInt() Parses the input returns an integer onday”);
var b = parseFloat(“23.3
parseFloat() Parses the input and returns a floating-point number 33”);
Loops
var i;
for looping in javascript for (i = 0; i < 5; i
++
{ // code}
while (product.lengt
while execute a block of code while some condition is true h > 5)
{// some code}
do {
do… similar to while, but executes at least as the condition is applied after // code
while the code is executed }while (condition){
}
if (i <10)
break break and exit the cycle based on some conditions break;
if (j>10)
continue continue next iteration if some conditions are met continue;
if-else statements
if-else lets you set various conditions –
if (condition 1)
{
//execute this code
} else if (condition 2)
{
// execute new code
} else
{
// execute if no other condition is true
}
String Methods
Method Meaning Example
var a = “hackr.io”;
charat() finds character at a specified position
“hackr”.charcodeat(0);
returns the unicode of character at the specified
charcodeat()
position
will return 72
var a = “hackr.io”;
var arr = a.split(“”);
convert a string into array based on special
split()
character
will return an array of characters
h,a,c,k,r and so on..
accessing access a character of string using its index (doesn’t var a = “hackr.io”;
characters using [] work on some versions of ie) a[2] will return c
Escape characters
\' Single quote
\\ Single backslash
\b Backspace
\f Form feed
\n New line
\t Horizontal tab
\v Vertical tab
\r Carriage return
Regular Expressions
Regular expressions can be in the form of pattern modifiers, metacharacters, quantifiers
and brackets. Pattern modifiers
e evaluate replacement
i case-insensitive matching
u ungreedy pattern
Brackets
[abc] Find any of the characters between the brackets
[^abc] Find any character which are not in the brackets
Metacharacters
. Find a single character, except newline or line terminator
\w Word character
\W Non-word character
\d A digit
\D A non-digit character
\s Whitespace character
\S Non-whitespace character
\0 NULL character
\t Tab character
Quantifiers
n+ Matches string that contains at least one ‘n’
Numbers
The maximum numeric value that can be represented in
MAX_VALUE
JavaScript
var a = 3.1417
;
Returns the string with a number rounded to and a.toExponentia
toExponential()
written in exponential form l(2);
will give 3.14
e+0
Number
methods var a = 3.1417
;
Returns the string of a number with specific
toFixed() a.toFixed(2);
number of decimals will return 3.
14
var a = 3.46;
Returns string to the precision of the specified a.to{recision(
toPrecision() 2);
decimal
returns 3.5
var x = 23;
valueOf() Converts number object to primitive type x.valueOf();
E Euler’s number
exp(x) Value of Ex
Dates
Date() Creates a new date object with current date and time
Date(2019, 10, 21, 12, 24, Create a custom date object. Format – (yyyy, mm, dd, hh, min, s, ms). Except
58, 13) for year and month, all parameters are optional.
The day (date) of the month in the specified date according to universal time
getUTCDate()
(also available for day, month, full year, hours, minutes etc.)
Sets the day of the month for a specified date according to universal time (also
setUTCDate()
available for day, month, full year, hours, minutes etc.)
DOM mode
Document
nodes) canObject
be easily
Model)
manipulated
is the code
using
of the
JavaScript.
page structure. HTML elements (called as
Node
childNodes all child nodes of an element
properties
textContent Sets or returns the textual content of a node and its descendants
cloneNode() Clones an HTML element
Node
Inserts a new child node before a specified, existing child
methods insertBefore()
node
Element
Returns true if an element has any attributes, otherwise
methods hasAttribute()
false
Browser actions
defaultStatus Sets or gets the default text in the windows status bar
Window
frames Returns all <iframe> elements in the current window
properties
pageYOffset Number of pixels the current document has been scrolled vertically
prompt() Displays a dialogue box that prompts the visitor for input
availHeight Returns the height of the screen (excluding the Windows Taskbar)
Screen properties
availWidth Returns the width of the screen (excluding the Windows Taskbar)
colorDepth Returns the bit depth of the color palette for displaying images
User Events
1. Mouse
onmouseover when the mouse is moved over some element or its children
onmouseout User moves the mouse pointer out of an element or one of its children
2. Keyboard
3. Frame
4. Form
onchange when content of a form element like <input>, <select> and <textarea> changes
5. Drag
6. Clipboard
7. Media
ontimeupdate The playing position has changed (like in case of fast forward)
8. Animation
9. Other
10. Errors
throw Create custom error messages rather than standard JavaScript errors
finally block that is always executed whether there is error in execution or not
Error-values
Each error has a name and message property that define it.
Conclusion
This cheat sheet has all the functions of javascript. We have provided examples and
descriptions where necessary. Most functions are self-explanatory, however, feel free to
comment and let us know if you have any doubts or questions.
Happy scripting!
People are also reading:
Share:
Ramya Shankar
A cheerful, full of life and vibrant person, I hold a lot of dreams that I want to fulfill on my own. My
passion for writing started with small diary entries and travel blogs, after which I have moved on to
writing well-researched technical content. I find it fascinating to blend thoughts and research and
shape them into something beautiful through my writing.