The instantiation or calling-a-class-object operation creates an empty object. Many classes like to create objects with instances with a specific initial state. Therefore a class may define a special method named __init__(), as follows −def __init__(self) − self.data = [ ]When a class defines an __init__() method, class instantiation automatically invokes the newly-created class instance which is obtained by −x = MyClass()The __init__() method may have arguments. In such a case, arguments given to the class instantiation operator are passed on to __init__(). For example, >>> class Complex: ... def __init__(self, realpart, imagpart): ... ... Read More
To check if a variable exists in JavaScript, you need to check it against null as in the following code. Here, we’re checking the existence of variable myVar − var myVar = 20; if(myVar !== undefined && myVar !== null) { document.write("Variable exists"); }
Before you use a variable in a JavaScript program, you must declare it. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.Variables are declared with the var keyword as follows. You can also declare multiple variables with the same var keyword as follows − This is also you can assign values −var rank = 2; var points = 100;
The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.The new Boolean() is used to create a new object. Use the following syntax to create a boolean object.var val = new Boolean(value);ExampleLet us see an example of toString() method, which returns a string of either "true" or "false" depending upon the value of the object − JavaScript toString() Method var flag = new Boolean(false); document.write( "flag.toString = " + flag.toString() );
The addition operator is used to add two operands.ExampleYou can try to run the following code to work with Addition Operator − var a = 33; var b = 10; document.write("a + b = "); result =a + b; document.write(result);
It adds the right operand to the left operand and assigns the result to the left operand.ExampleYou can try to run the following code to learn how to work with Addition Assignment Operator − var a = 33; var b = 10; document.write("Value of a => (a += b) => "); result = (a += b); document.write(result); document.write(linebreak);
A boolean variable in JavaScript has two values True or False.ExampleYou can try to run the following code to learn how to work with Boolean variables − 35 > 20 Click for result function myValue() { document.getElementById("test").innerHTML = Boolean(35 > 20); }
JavaScript is untyped language. This means that a JavaScript variable can hold a value of any data type. To declare variables in JavaScript, you need to use the var keyword. Whether it is a number or string, use the var keyword for declaration.Here’s how you can declare numbers in JavaScript −var points = 100; var rank = 5;ExampleYou can try to run the following code to learn how to declare number in JavaScript −
This operator is just like the >>operator, except that the bits shifted in on the left are always zero i.e. xeroes are filled in from the left.ExampleYou can try to run the following code to learn how to work with unsigned right shift operator − var a =-14; var b =2; // Shift right two bits document.write("(a >>> b) => "); result =(a >>> b); document.write(result);
There's no validate method as almost anything is a valid URL. There are some punctuation rules for splitting it up. Without any punctuation, you still have a valid URL.Depending on the situation, we use following methods.If you trust the data, and just want to verify if the protocol is HTTP, then urlparse is perfect.If you want to make the URL is actually a true URL, use the cumbersome and maniacal regexIf you want to make sure it's a real web address, use the following codeExampleimport urllib try: urllib.urlopen(url) except IOError: print "Not a real URL"Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP