Bài đăng

Hiển thị các bài đăng có nhãn javascript Beginner

Extra small numbers in javascript

Hình ảnh
     Big numbers can write using the below format in javascript. Example Program:- (Editor) Editor is Loading... Output:- Advertisement

How to convert Hexadecimal, octal,binary

Hình ảnh
     In javascript we can easy to convert any numbers to corespoinding hexadecimal, octal or binary value using toString() method. Syntax    variable.toString()      //convert to String    variable.toString(2)    //convert to Binary    variable.toString(8)    //convert to Octal    variable.toString(16)  //convert to Hexadecimal Example    var num=66;    num.toString();     //return "66"    num.toString(2);   //return "1000010"    num.toString(8);   //return "102"    num.toString(16); //return "42" Example Program:- (Editor) Editor is Loading... Output:- Advertisement

parseInt() in javascript

Hình ảnh
     The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems). Syntax    parseInt(string, radix); string      The value to parse. If string is not a string, then it is converted to a string (using the ToString abstract operation). Leading whitespace in the string is ignored. radix      An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify 10 for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10. Description      The parseInt function converts its first argument to a string, parses it, and returns an integer or NaN. If not NaN, the retur...

parseFloat() in javascript

Hình ảnh
     The parseFloat() function parses a string argument and returns a floating point number. parseFloat is a top-level function and is not associated with any object.      parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed.      If the first character cannot be converted to a number, parseFloat returns NaN.      For arithmetic purposes, the NaN value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is NaN. If NaN is passed on to arithmetic operations, the operation results will also be NaN.      parseFloat can also parse and return the value Infinity. You can use the isFinite function to de...

toFixed() in javascript

Hình ảnh
     The toFixed() method formats a number using fixed-point notation. digits Optional. The number of digits to appear after the decimal point; this may be a value between 0 and 20, inclusive, and implementations may optionally support a larger range of values. If this argument is omitted, it is treated as 0. Returns A string representation of numObj that does not use exponential notation and has exactly digits digits after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length. If numObj is greater than 1e+21, this method simply calls Number.prototype.toString() and returns a string in exponential notation. Throws RangeError If digits is too small or too large. Values between 0 and 20, inclusive, will not cause a RangeError. Implementations are allowed to support larger and smaller values as well. TypeError If this method is invoked on an object that is not a Number. Synt...

toPrecision() in javascript

Hình ảnh
     The toPrecision() method returns a string representing the Number object to the specified precision.      A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits. See the discussion of rounding in the description of the Number.prototype.toFixed() method, which also applies to toPrecision() .      If the precision argument is omitted, behaves as Number.prototype.toString() . If the precision argument is a non-integer value, it is rounded to the nearest integer. Syntax    number.toPrecision([precision]); Example    (3.666621).toPrecision(2)  //3.37 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

toExponential() in javascript

Hình ảnh
     The toExponential() method returns a string representing the Number object in exponential notation. Parameters fractionDigits      Optional. An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number. Returns      A string representing a Number object in exponential notation with one digit before the decimal point, rounded to fractionDigits digits after the decimal point. If the fractionDigits argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely.      If you use the toExponential() method for a numeric literal and the numeric literal has no exponent and no decimal point, leave a space before the dot that precedes the method call to prevent the dot from being interpreted as a decimal point.      If a number has more digits than requested by the fraction...

Math.min() in javascript

Hình ảnh
     The Math.min() function returns the smallest of zero or more numbers. min() is a static method of Math, you always use it as Math.min(), rather than as a method of a Math object you created (Math is not a constructor).      If no arguments are given, the result is Infinity.      If at least one of arguments cannot be converted to a number, the result is NaN. Syntax    Math.min([value1,value2,...]); Example    Math.min(20,50,36,2);  //2    Math.min(-3,3,0,99);  //-3 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Math.max() in javascript

Hình ảnh
     The Math.max() function returns the largest of zero or more numbers. max() is a static method of Math, you always use it as Math.max(), rather than as a method of a Math object you created (Math is not a constructor).      If no arguments are given, the result is -Infinity.      If at least one of arguments cannot be converted to a number, the result is NaN. Syntax      Math.max([value1,value2,value3,...]); Example Math.max(50, 10);   //  50 Math.max(-1, -200); // -1 Math.max(-999, 2);  //  2 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Math.floor() in javascript

Hình ảnh
     The Math.floor() function returns the largest integer less than or equal to a given number. floor() is a static method of Math, you always use it as Math.floor() , rather than as a method of a Math object you created (Math is not a constructor). Syntax    Math.floor(value); Example    Math.floor( 40.95); //  40    Math.floor(-48.95); // -49 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Math.random() in javascript

Hình ảnh
     The Math.random() function returns a floating-point, pseudo-random number in the range [0, 1] that is, from 0 (inclusive) up to but not including 1 (exclusive), which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user. Note:  Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security.  Syntax    Math.random(); Example    Math.random();  //0 to 1 Numbers    (Math.floor(Math.random() * 100) + 1) // 1 to 100 Numbers Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Math.round() in javascript

Hình ảnh
     The Math.round() function returns the value of a number rounded to the nearest integer. If the fractional portion of number is 0.5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than 0.5, the argument is rounded to the next lower integer.      Because round() is a static method of Math, you always use it as Math.round() , rather than as a method of a Math object you created (Math has no constructor). Syntax    Math.round(number); Example Math.round(19.39); //19 Math.round(19.7); //20 Math.round(-19.04); //-19 Math.round(-19.51); //-20 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Math.ceil() in javascript

Hình ảnh
     The Math.ceil() function returns the smallest integer greater than or equal to a given number. ceil() is a static method of Math, you always use it as Math.ceil(), rather than as a method of a Math object you created (Math is not a constructor). Syntax    Math.ceil(number); Example    Math.ceil(.97);   // 1    Math.ceil(0.3);     // 1    Math.ceil(3);     // 3    Math.ceil(7.003); // 8 Example Program:- (Editor) Editor is Loading... Output:- Advertisement

abs() pow() and sqrt() in javascript

Hình ảnh
Math.abs()    - The Math.abs() function returns the absolute value of a number. Math.pow()  - The Math.pow() function returns the base to the exponent power, that is, baseexponent. Math.sqrt()   - The Math.sqrt() function returns the square root of a number. Example Program:- (Editor) Editor is Loading... Output:- Advertisement

Simple example for array in javascript

Hình ảnh
     The JavaScript Array object is a global object that is used in the construction of arrays; which are high-level, list-like objects. Example var ar=[1,2,3,4,5]; Example Program:- (Editor) Editor is Loading... Output:- Advertisement